0

So, I'm hacking something related to nameref and during the hacking, I find on the beginning of page 3 of the nameref manual on my computer (dated 2016/05/21) that

We redefine \label so that it also writes the name of the current section to the .aux file; if the name ends in a dot, we zap it.

I checked the newest documentation of nameref in the CTAN and this sentence is still there. Actually, I don't want this functionality to work for my own \newcounter since it does end with a dot.

So, my questions are

  1. Why do they do something like if the name ends in a dot, we zap it?

  2. Is there a good way to hack this locally to make \label aware of the ending dot? Why locally? I'm assuming that there exists a good reason for the first question so that I'm not recommended to erase this entirely.

  3. Actually I understand that this functionality is realized by this definition on the same page

    \def\NR@strip@period#1.\ltx@empty#2\@nil{#1}

    But, I'm quite confused by its use since this \def is followed by three commands in a row while the usual one looks just like \def\newcommand<argument>\oldcommand. So, can anyone explain how this line works to me? Or maybe point to me some reference. So that I can myself figure out the hacking.

1 Answers1

2

why that way? it's all a long time ago but while some styles treat the title as a sentence and have

Introduction.
Blah blah...

in a generated reference you would want it to say "in the Introduction we describe.. never "in the Introduction. we describe ....` so you need the . to go.

Unlike \newcommand the primitve \def allows delimited arguments that end at a specied token.

If you go

\def\zz#1.{the argument is #1}

then \zz will take as argument everything up to the first . so

\zz The Introduction.

would produce the argument is The Introduction with no . so that's almost what is wanted except if the section title didn't have a . this would give a low level error that the argument never ended, so the trick is to use a form such as

\def\zz#1.#2\relax{#1}

and always supply the . and \relax

now if #1 is the argument from \section then

\zz#1.\relax

can be called as

\zz The Introduction..\relax

now we get #1 is The Introduction and #2 is . which is discarded

and if there was no . in the original the call is

\zz The Introduction.\relax

and here again #1 is The Introduction and now #2 is empty and not used.

\NR@strip@period is a slightly more complicated version of this \zz idea.

David Carlisle
  • 757,742