# Tag Info

3

If you can use LuaLaTeX instead of either pdfLaTeX or XeLaTeX, it's straightforward to set up Lua functions along the lines of the example you gave as well as TeX "wrapper macros" that call the Lua functions with the required inputs. % !TEX TS-program = lualatex \documentclass{article} %% Lua-side code \usepackage{luacode} \begin{luacode} function pfunc ...

1

Use \@ifdefinable: \documentclass{article} \makeatletter \newcommand\factory[2]{% \expandafter\@ifdefinable\csname#1\endcsname{% \global\@namedef{#1}{#2}% }% } \makeatother \begin{document} \begin{enumerate} \item \factory{foo}{This is foo.} \foo \item \factory{boo}{This is boo.} \boo \end{enumerate} \begin{enumerate} \item ...

11

If you use \edef you need to reset \\ and \hline afterwards, but it is typically not safe to use \edef with LaTeX input. The second form doesn't repeatedly expand the tokens. Please always make examples complete documents, as below. \documentclass{article} \begin{document} {\let\\=\relax \let\hline=\relax \xdef\mmm{\hline A & B\\} \xdef\mmm{\mmm\hline ...

8

There are several ways for appending tokens to the replacement text of a macro. The simplest one is with etoolbox: \usepackage{etoolbox} [...] \def\mmm{\hline A & B\\} \appto\mmm{\hline C & D\\} \appto\mmm{\hline 1 & 2\\\hline} \begin{tabular}{|c|c|}\mmm\end{tabular} Without packages, ...

1

\documentclass{article} \makeatletter \def\zz#1 {\def\zza{#1}% \ifx\zza\zzb\else \stepcounter{enumi}% Field \theenumi\ is \fbox{\zza}\par \expandafter\expandafter\expandafter\zz \fi} \def\zzb{\relax?} \begin{document} \expandafter\zz\@@input testdata.txt\relax? \end{document}

2

With the help of l3regex we can get rid of blank lines preceding \item or \end{enumerate} and add \mymessage in the appropriate spots. \documentclass{article} \usepackage{environ,xparse,l3regex} \let\latexenumerate\enumerate \let\endlatexenumerate\endenumerate \newcommand{\mymessage}{\mbox{}\\End of item} \ExplSyntaxOn \RenewEnviron{enumerate}{% % ...

5

Here is a way without packages. One must be careful to avoid a blank line before \item invocations. The MWE shows how it is set up to affect only enuemerate and not related environments like itemize. \documentclass{article} \def\message{This is the end of item.} \let\svitem\item \let\svenumerate\enumerate \let\svendenumerate\endenumerate% ...

4

Not the best way, but it works for the first level of enumeration, however, not for empty \item commands. I've prepended \item with \newline (Is it really necessary?) -- this does not work for the first item, of course and the last \item will not get it unless, \endenumerate is prepended to. \documentclass{article} \def\mymessage{This is the end of ...

2

Using lambda.sty (for fun) The lambda.sty package define fully expandables conditionnals and lists. In a similar way, the following macros define binary trees and a \BSTSort macro which can tree-sort a lambda list. It is not exactly quicksort, but is very similar. \documentclass{article} \usepackage{lambda} \makeatletter % Tree Data type (Similar to ...

Top 50 recent answers are included