[tex-eplain] \mark problem solved

Gerald Tenenbaum gerald.tenenbaum at ciril.fr
Sun Feb 11 15:13:16 CET 2007


Hi everybody,

In certain situations, one needs the argument of 
\mark not be expanded for some purposes and to be 
expanded for others. This occurs for instance 
when one wants to automatically modify the 
headline according to the title of the running 
section.
Then, we need the \noexpand in the \mark, but not 
in the regular typeset.  So we have to use the 
infamous LaTeX
\protect and redefine it according to the situation, for instance:

\input eplain.tex
\newtoks\runningtitle
\headline={\hfil\the\runningtitle\hfil}
\let\newtitlemark\relax

\def\section#1#2{\mark{\par\newtitlemark\noexpand\else{#1\ #2}}
     \goodbreak\noindent {\let\protect\relax\bf\S\  #1\ $\,$#2}\smallskip
     \runningtitle={\iftrue\botmark\fi}
     \shortmark{#1\ #2}}
\let\protect\noexpand

\def\shortmark #1{\mark{#1\noexpand\else #1}
                     \def\newtitlemark{#1}}

\def\thmword{Theorem}
\definexref{th1}{123}{thm}
First
\section{1}{Proof of \protect\ref{th1}}
\null\vfil\eject
Hey one, \ref{th1}.
\mark{Hey, \noexpand\ref{th1}.}
\null\vfil\eject
ddd
\par
MARK \botmark
\end

In all the marks, \ref gets stored unexpanded, 
but in the actual title print, \protect is locally
redefined.

An alternative is to use the toks, eliminating the needs for any \protect:

\input eplain.tex
\newtoks\runningtitle
\headline={\hfil\the\runningtitle\hfil}
\let\newtitlemark\relax
\newtoks\title

\def\section#1#2{\title={#2}%
     \mark{\par\newtitlemark\noexpand\else{#1\ \the\title}}
     \goodbreak\noindent {\bf\S\  #1\ $\,$#2}\smallskip
     \runningtitle={\iftrue\botmark\fi}
     \shortmark{#1\ \the\title}}

\def\shortmark #1{\mark{#1\noexpand\else #1}
                     \def\newtitlemark{#1}}

\def\thmword{Theorem}
\definexref{th1}{123}{thm}
First
\section{1}{Proof of \ref{th1}}
\null\vfil\eject
Hey one, \ref{th1}.
\mark{Hey, \noexpand\ref{th1}.}
\null\vfil\eject
ddd
\par
MARK \botmark
\end


Both these elegant solutions have been found by Stepan Kasal.
Thanks again, Stepan!

Regards to everyone,

Gérald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/tex-eplain/attachments/20070211/3b76f421/attachment.html 


More information about the tex-eplain mailing list