# Tag Info

17

An individual macro may only have one definition, but a combination of macros can parse the input stream: \def\aprint#1at#2,#3{The text #1'' shall be printed at $#2 \abovewithdelims()0pt #3$} \def\bprint#1by#2,#3{The text #1'' shall be printed by #2 and #3 Doe} \def\print#1#2{\csname#2print\endcsname{#1}#2} \print{Testtext}at 2,3 ...

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

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{} %%% ...

11

The [a=b] syntax used by graphicx package is defined by the keyval package which you can use to define similar commands. (xkeyval, pstricks, pgf, l3keys aslo define similar argument parsers, but it probably makes sense to use keyval if you want to fit in with graphix. See texdoc keyval for more details.

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} ...

9

This should be what you want. The mandatory argument to \fa should be a four character string: First byte: 1 or 2 (one way or two way) Second byte: S or M (single or multi head) Third byte: D or N (deterministic or non deterministic) Fourth byte: + or - (with or without stack) The optional argument is the number of heads, while the macro \fa can be ...

7

The first closing curly brace is too late, fixed: \newcommand*{\citea}[1]{\autocite{#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: ...

5

Once TeX has tokenized input, which occurs for example when you save the input in a macro, then it's not generally straight-forward to alter the nature of the tokens. In particular, this restricts our ability to use verbatim or verbatim-like input in the arguments and definitions of macros. The \href command needs to use a verbatim-like approach to allow for ...

5


5

I think I now understand what's happening here. The syntax for \let is as follows \let<control sequence><equal><one optional space><token> If I write, where * indicates a space \let\ae@sptoken=* then * is just interpreted as the <one optional space> and the next token is grabbed for the \letting. In the case of ...

5

Here's an approach which is initially a little top heavy but allows you to make various formatting choices down the line: \documentclass{article} \makeatletter \let\@xp\expandafter \newcommand\set{\ae@set} \def\ae@set(#1){%% \@ifnextchar;%% {\@ae@set(#1)}%% {\ae@@set(#1)}} \def\@ae@set(#1);{\ae@@set(#1)->#1;} \def\ae@@set(#1)->#2;{%% ...

4

This is clearly a bug in tex4ht support for listings. When you look at generated code, you can see: <!--l. 13--><pre class="listings"><span class="cmtt-10x-x-109"> </span><br /><span class="label"><a id="x1-2r1"></a></span><span class="cmtt-10x-x-109">\$</span><span ...

4

Short answer: it requires indeed an extreme amount of work Long answer: No, you don't want to know the details. I don't want to write them. Really... (Update: There is a good explanation by @percusse here) Tikz does not use the TeX macro engine. It builds its own parser which basically processes all the characters after a given command (such as \tikz, ...

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 ...

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 %-- ...

3

If I understand your wish, you need to use the following macros: \newcount\tmpnum \def\sedef#1{\expandafter\edef\csname#1\endcsname} \def\expandcsname#1{\expandafter\ifx\csname#1\endcsname\relax \else \csname#1\endcsname\fi} \def\brk#1#2#3{\bgroup\def\brkLines{#2}\ifx+#1\tmpnum=0 \brkA#3{}% \else\tmpnum=1 ...

3

The \\ is the reason for the error, if you remove it, your code succeed: \documentclass{minimal} \usepackage{tikz} \usetikzlibrary{shapes} \newenvironment{UMLDiagramm}{% \newcommand{\Class}[3]{\node[class](##1){\underline{##2}\nodepart{second}{##3}};}% \begin{tikzpicture}[% class/.style={draw, rectangle split, rectangle split parts=2, ...

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


3

The LaTeX2e kernel defined \@namedef{<csname>} that could be used exactly for this purpose, as it is defined as: \def\@namedef#1{\expandafter\def\csname #1\endcsname} It sets up the definition of its argument as a control sequence, awaiting the actual replacement text as part of the usual \def construction. \documentclass{article} \makeatletter ...

3

Since there are other solutions of the “front end” here I just a the solution for parsing the argument. This is just a simple “reader”: it reads a certain element and checks if it's equal to some predefined cases, and, in case it is not, it does what it's inside the F argument (…:nnnF). First element, 1 or 2, otherwise does nothing (no error). Second ...

2

thanks to @David Carlisle 's comment Macros: { xspace: '', ensuremath: '' } did the trick.

1

Here's an application of expl3: for splitting I cycle the requested number of times through the input string, picking up the items corresponding to the cycle and forming a sequence; for rebuilding it's just the reverse: I cycle over the sequence elements picking up the first element, the second one and so on from each item. \documentclass{article} ...

1


1

I think that you are trying to do something like this: \documentclass{article} \usepackage{comment} \newif\ifTeacher\Teachertrue \newcommand\teacher[1]{\ifTeacher#1\else\relax\fi} \begin{document} \teacher{This is a remark for the teacher} \Teacherfalse \teacher{This should be ignored.} This is for everyone. \end{document} By using \Teachertrue and ...

1

Lambda ala JavaScript anonymous functions, and python, pick your style and stay within the LaTeX/TeX paradigm it is better. \documentclass{article} \usepackage{lipsum} \usepackage{fp} % function (callback, args) { % return %} \def\func (#1,#2){% \ifcsname#1\endcsname% \csname#1\endcsname{#2}% \else% #1,#2 \fi% } \begin{document} ...

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