[texhax] Low-level TeX question: string substitution macro

Uwe Lück uwe.lueck at web.de
Wed Apr 22 18:38:20 CEST 2009


At 15:44 22.04.09, Toby Cubitt wrote:
>Uwe Lück wrote:
> > At 10:39 22.04.09, Toby Cubitt wrote:
> >> Once you've processed the document the requisite number of times to get
> >> the cross-references right, you can then run the original source file
> >> through the sed script to produce a new LaTeX source file, from which all
> >> the cleveref commands have been stripped out and replaced by equivalent
> >> standard LaTeX, suitable for submitting to a journal (or sending to a
> >> colleague) who doesn't have cleveref installed.
> >
> > The last thing is quite important, I think, so "poorman" is almost
> > inevitable.
>
>The problem is mainly with publishers who don't actually use TeX to
>produce the final type-set version from the LaTeX source, but instead
>transform the LaTeX into their own in-house mark-up language before
>sending to press. Such publishers place restrictions on which (if any)
>LaTeX packages can be used, since they likely won't work unless supported
>explicitly by their transformation scripts.
>
> > When cleveref finds *one* <clever> in "poorman" mode, it tells an external
> > program to replace *all* occurrences of <clever> by <plain>.
>
> > To replace sed by TeX, I propose writing to <out>=\jobname.ffd as follows:
> >
> >     {\let\ref\relax \let\cref\relax \let~\relax %% ~ added after 
> quoting -- UL
> >      \immediate\write<out>{\string\AddReplacement{<clever>}{<plain>}}}
>
>In the latest cleveref version (not yet on CTAN), I also use sed addresses
>to cope with babel language changes. I don't know how easy that would be
>to replicate with fifinddo.

It seems if cleveref is clever enough to write to files under babel, then 
fifinddo needn't care about babel anymore. Users are urged to do the file 
processing *before* any typesetting packages are loaded. It expects 
(currently) that the tilde is the only active character indeed. (Otherwise 
one could turn almost all characters ``other'' at reading.)

> > fifinddo is in my view better suited for reworking TeX files than those
> > other mere string handling packages.
>
>Could be. But cleveref only needs very simple substitutions, so sed is
>more than sufficient. The only advantage I see in using fifinddo is that
>some (especially Windows) users might not have sed installed, whereas if
>they're using cleveref they must have TeX installed. On the other hand,
>they'll have to install fifinddo (or whatever other TeX string
>substitution package), and it's not completely clear that's any easier...

The difference between cleveref and fifinddo concerning installing is that 
fifinddo really isn't needed for typesetting. It is an alternative to sed, 
not to cleveref, and installing a LaTeX package should be easier than 
installing an executable/application.

Concerning string handling, fifinddo is ridiculous (at present, but there 
may be little need to change it), it is only a nucleus of string handling. 
But the other string handlers don't care about where strings come from and 
where they go. fifinddo acts on files and provides a script language for 
this (or setup for creating script languages).

>If someone sends me a working patch against cleveref.dtx, I'd be happy to
>consider including it. I'm unlikely to implement it myself.

OK, it is clear what to do, and the rest may happen off the list.

I wouldn't say "patch". cleveref should just have an additional option 
"poorman-tex" that writes (La)TeX-like output instead of sed output -- 
hoping there will be some TeX package that can make use of it. And an 
expansion of fifinddo should be such a TeX package. Or other string 
handlers are expanded to act on files. Or datatool learns to consider TeX 
code "data".

But this won't happen today.

cleveref might have an alias "poorman-sed" for "poorman", and additional 
options "poorman-awk" and "poorman-perl".

TeX forever!

     Uwe.



More information about the texhax mailing list