[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX] Insert counter in Emacs tex file

From: David Kastrup
Subject: Re: [AUCTeX] Insert counter in Emacs tex file
Date: Sat, 25 Aug 2018 20:48:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Joost Kremers <address@hidden> writes:

> On Fri, Aug 24 2018, Rodolfo Medina wrote:
>> Hi all...
>> In a MusiXTeX document, you insert several \bar(s) TeX commands,
>> that I
>> manually count typing a number next to each occurence of `\bar':
>>  \bar %1
>>  ...
>>  \bar %2
>>  ...
>>  \bar %3
>> and so on.  Of course, it gets very uncomfortable when editing the
>> document and
>> adding, in the middle of it, new \bar-s: then I have to re-write all
>> the
>> numbers, that may be dozens or hundreds...!  So I was wondering if
>> was possible
>> to have an automatic \bar numbering within my Emacs tex file...
> I have a bunch of functions to help me with something similar. The
> following function allows me to renumber counters used as labels in a
> TeX document:


It's worth pointing out that query-replace-regexp can accept calculated
replacement texts.

So one can write stuff like

C-M-% \\bar %[0-9]+ RET \\bar %\,(+ 15 \#) RET

in order to replace the respective statements, with the first
replacement getting the number 15 then (assuming that you don't need to
replace anything before that).

The documentation mentions:

       For computing replacement strings for ‘\,’, the ‘format’ function is
    often useful (*note (elisp)Formatting Strings::).  For example, to add
    consecutively numbered strings like ‘ABC00042’ to columns 73 to 80
    (unless they are already occupied), you can use

         M-x replace-regexp <RET> ^.\{0,72\}$ <RET>
         \,(format "%-72sABC%05d" \& \#) <RET>

which is a bit tongue-in-cheek since it refers to conventions used for
mitigating the damage from dropping stacks of punch cards.

David Kastrup

reply via email to

[Prev in Thread] Current Thread [Next in Thread]