[texhax] Last char of a string

Uwe Lueck uwe.lueck at web.de
Thu Jul 7 21:58:49 CEST 2011


"Paul Isambert" zappathustra at free.fr[mailto:zappathustra at free.fr] wrote 07.07.2011 21:13:13:
> Le 07/07/2011 18:11, Michael Barr a écrit :
>> No, I am not using pdftex. For the time being the journal archives
>> everything as dvi, along with ps and pdf. But someone pointed me to
>> xstring which has a procedure called IfEndWith and that works.
>>
>
> PDFTeX produces DVI too. That's the default engine in distributions,
> which is why I said you probably didn't know you were using it. See
> what's printed at the beginning of the log file ("This is PDFTeX...").

In any case, (a) the original question was about *any* punctuation,
which may as well be a question mark, (b) some macros such as
\section need to be modified. The conceptually most straightforward
way doing this is defining some \extramacro and applying it about as

    \let\wasSection\Section
    \renewcommand\Section[1]{\wasSection{\extramacro{#1}}}

or 

    \renewcommand\Section[1]{\wasSection{#1\extramacro}}

The first version was just to cover Paul's approach. The second may be
more straightforward and refers to Donald's idea from January 2010,
about as

    \newcommand\extramacro{\ifnum\spacefactor>1000 \else.\fi}

A better name for \extramacro then would be something like \ensurepunct.
Something like this is in some theorem packages too, maybe even amsthm.

Note how simple this looks and that it covers more cases than the dot.

There is a problem with redefining LaTeX arguments with optional arguments,
here \section[ELSE-ENTRY]{MAIN-TITLE}.
I just realize that I am too tired to solve it right now. However,
nobody else has considered this difficulty so far ... 

This case also involves the problem of making this thing robust, well

        \DeclareRobustCommand\extramacro{\ifnum\spacefactor>1000 \else.\fi}

but it also must go into the optional argument. (?)

I had not thought this would take so much, what a pity, I had to something
more important, now it's too late.

    Uwe.



More information about the texhax mailing list