When you say
\def\temp{This |doesn't work|, though :-(}
the catcode of |
is fixed and setting \catcode`|=\active
has no effect when the expansion of \temp
is performed: the |
characters in the replacement text have category code 12.
One can use \scantokens
to reassign category codes, but the macros must be expanded before \scantokens
comes into play:
\makeatletter
\begingroup
\lccode`\~=`\|
\lowercase{\endgroup
\def~#1~{\textbf{#1}}%
}
\def\iPrint#1{%
\begingroup
\catcode`\|=\active
\protected@edef\reserved@iprint{\noexpand\scantokens{#1\noexpand\empty}}\reserved@iprint
\endgroup
}
\makeatother
If the input to \iPrint
is known to be only text or a macro (say \iPrint{\temp}
), then the simpler
\def\iPrint#1{%
\begingroup
\catcode`\|=\active
\scantokens\expandafter{#1\empty}%
\endgroup}
would work. If the argument is more complicated (text and macros), then the more complicated approach with \protected@edef
appears to be necessary; it will expand all macros, but won't go too much deeply with "protected" macros.
The \empty
at the end of the argument to \scantokens
is customary to avoid a spurious space: \scantokens
actually emulates the input of a file and all files are implicitly terminated with an empty line. Inside \protected@edef
it mustn't be expanded, so we add \noexpand
in front of it.
(Thanks to Bruno Le Floch for correcting an inaccuracy.)
Best Answer
Use can write Greek directly with the
alphabeta
package.