# Tag Info

2

For example using OPmac: \input opmac \def\MyFormatter{\afterassignment\MyFormatterA \def\tmpb} \def\MyFormatterA{\replacestrings{p}{{\bf p}}\replacestrings{k}{{\bf k}}% \replacestrings{m}{{\it m}\/}\replacestrings{t}{{\it t}\/}\tmpb} \MyFormatter{Supermarket} \bye

4

An approach using catcodes that works if the \MyFormatter appears in the clear and is not part of an argument. As egreg pointed out in this regard, \mbox{\MyFormatter{Supermarket}} fails. However, I jokingly retort in my comment that the way to get around the fail-case is to put the \mbox inside the MyFormatter, not the other way around. Of course, the ...

6

It's easy and flexible with regular expressions: \documentclass{article} \usepackage{xparse,l3regex} \ExplSyntaxOn \NewDocumentCommand{\myformatter}{m} { \tl_set:Nn \l_tmpa_tl { #1 } \regex_replace_all:nnN { ([kp]+) } { \c{textbf}\cB\{ \1 \cE\} } \l_tmpa_tl \regex_replace_all:nnN { ([mt]+) } { \c{textit}\cB\{ \1 \cE\} } \l_tmpa_tl \...

7

Here's a straightforward solution using expl3. If you need it to work in subgroups \MyFormatter{Supermarket and \MakeUppercase{Supermarket}} you can check this solution. \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand \myformatter { +m } { \xmllmx_myformatter:n { #1 } } \cs_new_protected:Npn \xmllmx_myformatter:n #1 { \tl_set:Nn \l_tmpa_tl { #1 } ...

0

This seems to work, although using \g@addto@macro seems more reasonable. \documentclass{article} \def\mytable{} \makeatletter \newcommand{\myitem}[2]{% \protected@edef\mytable{\mytable #1 & #2 \\}% } \makeatother \begin{document} \myitem{\textbf{foo}}{bar} \myitem{one}{two} \begin{tabular}{cc} \mytable \end{tabular} \end{document}

2


3

This is only a demonstration of applying \str_case:nnTF, \str_case_x:nn and \tl_case:nnTF. The cases for :cnTF etc. have been explained already in comments to the question. The difference between \str_case_x and \str_case is the expansion of arguments. The difference between a \tl.. and \str.. is that for a string the catcodes of the characters are all ...

5

Alan has shown the two ways of sharing code at run time, however the other way is to share code development, but extract separate copies of the code to be loaded into the document at run time. That is used for the two classes that you mention: article and book are almost identical in all respects except for some different defaults for \flushbottom, \...

4

There are basically two ways to do this. You can put all the code into a single .tex file and then inside each class you would use: \input{common_code} This is the simplest method, and if the code is only usable within the custom classes, then is probably the most straightforward approach. Alternatively, you could package the shared code as a package, ...

Top 50 recent answers are included