# Tag Info

12

If the argument of \aaa is expected to be a string of characters, then \catcode@=11 \def\aaa#1{\a@a#1\@nil} \def\a@a#1{\ifx#1\@nil\expandafter\empty\else#1-\expandafter\a@a\fi} \catcode@=12 \aaa{abcde} \bye will do. If the argument is more complicated, with braced groups or macros, it's more difficult. This is fully expandable, and ...

11


11

The following example uses the space as terminator and supports grouping of letters with braces including empty braces. The solution is expandable: \def\aaa#1 {% \aaaX#1\empty\empty } \def\aaaX#1#2{% #1% \ifx\empty#2\longempty \expandafter\gobble \else -% \expandafter\aaaX \fi {#2}% } \long\def\longempty{} \long\def\gobble#1{} %%% ...

9

\documentclass{article} \makeatletter \expandafter \renewcommand \expandafter\textdagger \expandafter{% \expandafter\@inmatherr \expandafter\textdagger \textdagger} \makeatoher \begin{document} \textdagger $\textdagger$ \end{document} The above shows the general technique but in this case you already get a warning, \textdagger by default makes LaTeX ...

9

The behavior of \textdagger is shared by all commands that are defined with \OMS-cmd, so a way to get errors when they're used in math mode is to change \@inmathwarn in the definition of \OMS-cmd with \@inmatherr. See Why does \textbackslash render as "n" in math mode? for more information about the issue. \documentclass{article} ...

6

Please always post complete documents showing all required packages. You don't need tracing to see the next token, it is explicit in the source \endgroup so you just need to move it into the two branches. \documentclass{article} \usepackage{fixltx2e,color} \begin{document} \makeatletter \def\md@err{*} \def\@hmno[#1]{% \endgroup \textsubscript{#1}} ...

6

\documentclass{article} \usepackage{etoolbox} \begin{document} \def\TrimBraces#1#2{\expandafter\zzz\expandafter#1\expandafter{\expandafter\zz#2\zz}} \def\zz#1\zz{#1} \def\zzz#1#2{\expandafter\def\expandafter#1\expandafter{#2}} \def\a{Test} \TrimBraces\x\a \show\x %-- should be ->Test % OK \def\b{{Test}} \TrimBraces\x\b \show\x %-- should be ->Test ...

6

My solution is only a little alternative to David's solution. The main point is the same: TeX removes outer braces from separated parameter if they exist: \def\aa#1\separator{...} \aa {text}\separator -- #1 is text \aa {text}b\separator -- #1 is {text}b And my solution: ...

4

Here's my take; it is assumed that \@nil doesn't appear in the expansion of the second argument. \documentclass{article} \makeatletter \def\TrimBraces#1#2{\expandafter\TrimBraces@aux#2\@nil{#1}} \def\TrimBraces@aux#1\@nil#2{\def#2{#1}} \makeatother \def\a{Test} \TrimBraces\x\a \show\x %-- should be ->Test \def\b{{Test}} \TrimBraces\x\b \show\x %-- ...

4

The answer by @egreg includes a mistake: the hyphen after the last letter isn't expected by the author of the question. There is full expanable solution which solves it: \def\aaa #1{\ifx\end#1\end\else \aaaB #1\end\fi} \def\aaaB #1#2\end{#1\aaaC#2\end} \def\aaaC #1{\ifx\end#1\empty\else -#1\expandafter\aaaC \fi} \aaa {abcde} \bye Edit: I've added one ...

3

%!TEX TS-program = pdftex \catcode@=11 \long\def\@firstoftwo#1#2{#1} \long\def\@secondoftwo#1#2{#2} \def\first#1{\@firstoftwo#1} \def\last#1{\@secondoftwo#1} \catcode@=12 \first{{+tokens1+}{--tokens2--}} \last{{+tokens1+}{--tokens2--}} \bye Of course, if you don't have (or want) anything to do with LaTeX. There's no need for \@firstoftwo while ...

3

The problem is the line \expandafter\protected@edef\expandafter\csname\tcsa\endcsname{\expandafter\csname\tcsb\endcsname}% Here, you are expanding \tcsa (which you don't actually need to do), but not expanding \csname before \protected@edef. The result is you redefine \csname: a Bad Thing! You need instead ...

3

The error you get Use of \csname doesn't match its definition is a clear sign that something has gone wrong in a definition, because it means you have redefined \csname. This happens in \expandafter\protected@edef\expandafter\csname\tcsa\endcsname{% \expandafter\csname\tcsb\endcsname} because the first \expandafter expands the second wich expands ...

2

The code below builds the list of hints via LaTeX's mechanism used for building toc, lof and lot and does not use enotez any more. It relies on the hyperref package being loaded so the hints in the list link back to the corresponding subproblem. The hints are printed as description lists, with \subsection*s between them as headings. The document body ...

1

After reading a bit about the pains involved in forcing *TeX to expand protected commands, I've changed my approach and used the BiBTeX facilities. The following code contains three command sets - one to print out the raw URL, one to format and link the URL using \url and one to create a \href hyperlink with some arbitrary text. \documentclass{article} ...

1

You need an \immediate version of \write (see Writing \\ to a File). The \protected@iwrite command has one argument more, where to give settings that are applied when writing. For writing a literal ~ you need to make it (temporarily) equivalent to \relax: \documentclass{article} \usepackage{amsrefs} \usepackage{xpatch} \makeatletter % get a copy of ...

Only top voted, non community-wiki answers of a minimum length are eligible