# Tag Info

1

The problem is the line: \cols=\expandafter{\the\cols \arabic{i}} \cols is a token register, thus \arabic{i} does not get expanded. Using an additional \expandafter and printing the counter value instead of \arabic helps: \cols=\expandafter{\the\expandafter\cols\the\value{i}} Complete example: \documentclass{article} \newtoks\cols \newcounter{i} ...

0

This can be done in a variety of ways as already suggested by the comments and other answer. Here are two solutions using pgffor and pgfkeys. This first solution works without using keys: \documentclass{article} \usepackage{pgffor} \usepackage{etoolbox} \makeatletter \newcommand\aeDynamicTable{\ae@dynamicTable} \def\ae@dynamicTable[#1]#2{%% ...

1

If you don't mind learning a little Python, the sagetex package can handle dynamic tables easily; after all Python is a powerful language. The documentation for sagetex is here and, in example.pdf, they construct Pascal's Triangle. Here's the code for something closer to what you asked for; the first row is 1 through N: \documentclass{article} ...

2

You may appreciate a LaTeX3 version; \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\Assign}{m} { \andrew_assign:n { #1 } } \NewDocumentCommand{\Assigned}{m} { \andrew_assigned:n { #2 } } % syntactic sugar for shortening code \cs_new:Npn \__andrew_seq:n #1 { g_andrew_assignee_#1_seq } \cs_new_protected:Npn ...

4

\documentclass{article} \makeatletter \def\Assign#1{% if \DP@#1 is defined append to it otherwise create it \ifcsname DP@#1\endcsname\def\DP@tmp{\csname DP@#1\endcsname,\@currentlabel} \else\def\DP@tmp{\@currentlabel} \fi \expandafter\xdef\csname DP@#1\endcsname{\DP@tmp} \typeout{ASSIGN: \csname DP@#1\endcsname} } \def\Assigned#1{% \csname ...

8

The environment enumerate adds a group, thus the changes to \DP@#1 are local and lost after the environment closes. Thus the example makes the definition global: \documentclass{article} \makeatletter \def\Assign#1{% if \DP@#1 is defined append to it otherwise create it \ifcsname DP@#1\endcsname \edef\DP@tmp{\csname DP@#1\endcsname,\@currentlabel}% ...

6

The syntax \def\Assigned#1{} is incorrect. The proper way is \expandafter\def\csname Assigned#1\endcsname{}. That allows your code to compile. Also, the \edef is localized and can't be accessed at a higher level. Changing it to \xdef remedies that. \documentclass{article} \makeatletter \def\Assign#1{% if \DP@#1 is defined append to it otherwise create ...

5

\documentclass{article} \newtoks{\MyTokenGlobal} \newtoks{\MyTokenLocal} %\usepackage{filecontents}% Commented to protect overwriting foo.tex \begin{filecontents}{foo.tex} \MyTokenGlobal={Global XXX} \MyTokenLocal={Local} \end{filecontents} \MyTokenGlobal={Global} \MyTokenLocal={Local XXX} \newcommand*{\MyInput}[1]{% \begingroup% ...

3

If you're only after a watermark on a page where a certain type of float appears, then you can tap into the shipout routine using atbegshi and condition on some counter magic with a float counter tracking mechanism: \documentclass{article} \usepackage{atbegshi,refcount,etoolbox,graphicx,xcolor} \usepackage{lipsum,afterpage} \newcounter{floatcntr} ...

3

if you need only the value and not its representation use : \newcommand\generator[1]{% \stepcounter{count}% \expandafter\edef\csname#1\endcsname{\arabic{count}}}

6

It's an expansion problem; \thecount needs to be expanded first: \documentclass{article} \newcounter{count} \newcommand\generator[1]% {% \stepcounter{count}% \expandafter\edef\csname#1\endcsname{\thecount}% } \generator{one} \generator{two} \begin{document} \one \two \end{document} This was similar to a problem I had and motivated A problem ...

3

We can't use numbers in LaTeX macros- see Defining commands/abbreviations that contain numbers and the links within for details. We can achieve close to your desired approach using a pgfplots-based approach by using styles: \pgfplotsset{ mystyle/.style={ solid, red, every mark/.append style={solid, fill=red}, mark=o}, ...

2

When a key is not set the value is \pgfkeysemptyvalue so you need to compare the value with this. One way is with \ifdefequal: \documentclass{article} \usepackage{tikz} \usepackage{etoolbox} \usepackage{overpic} \pgfkeys{ /icon/.cd, width/.initial, overlay/.initial, } \newcommand{\icon}[2][]{% {% ...

3

Not sure if this quite what you want, but you could try the following and see if it works: \documentclass[border=5]{standalone} \usepackage{pgfkeys} \begin{document} \pgfkeys{% /icon/.cd, width/.initial=, width/.default=, overlay/.initial=, overlay/.default=, % set defaults/.cd, .unknown/.code={% ...

3

\expandafter\includegraphics#3\expandafter[\options]{#2} the first \expandafter will expand the first token (only) of #3 but that is < so nothing expands. I think you intended \def\foo{\includegraphics#3}% \expandafter\foo\expandafter[\options]{#2}%

4

As mentioned in @egreg's comment, \includegraphics does not expand its first argument. A judicious use of \expandafter resolves that part of the problem. But also, \pgfkeys is getting confused by the = buried within the value you're passing. Try something like: \documentclass{article} \usepackage{tikz} \pgfkeys {/mypgf/.cd, options/.store in = ...

8

It's a category code problem, \jobname does not produce normal category codes when expanded. You can get around it by using \scantokens: \documentclass{article} \edef\filename{\scantokens\expandafter{\jobname\noexpand}-funny_name} \expandafter\def\expandafter\processline\filename.asy: #1.#2\relax{\gdef\errorline{#1}} \edef\oneline{errortest-funny_name.asy: ...

11

You have to expand \theexercise before doing the write: \documentclass{scrartcl} \usepackage{collect} \definecollection{answers} \newcommand\mycollect[1]{% \collect{answers} {\par\medskip\noindent\textbf{Answer to~#1}} {\par} {}{}% } \newenvironment{answer} {\begingroup\edef\x{\endgroup\noexpand\mycollect{\theexercise}}\x} {\endcollect} ...

9

For the sake of the exercise, here is a method without assignments. Don't expect miracles though, it should be fine when testing strings of letters and digits, however spaces will give false positives. This is a first sketch, I use xinttools as I am familiar with it. Some explanations added. \documentclass{article} \usepackage{xinttools} \makeatletter % ...

21

\in@{\foo}{\cslist} If you don't need pure expansion and can afford an assignment, that can simplify things \def\tmp{\expandafter\in@\expandafter{\foo}} \expandafter\tmp\expandafter{\cslist} only needs four \expandafter

21


31

\in@{\foo}{\cslist} % <--- What combination of \expandafter is needed here? If \foo is first expanded, then we have the problem, that \expandafter cannot jump over serveral tokens at once, also the number of tokens is not known. Therefore the latest token is expanded first. But at this stage we cannot add the \expandafter, because we have to insert the ...

3

LaTeX's protection mechanism only protects the macro, not its arguments. In LaTeX macro can be used/executed in different contexts: Normal typesetting context (\set@typeset@protect). \protect has the meaning of \relax. It does not touch the following macro which is executed normally. Display context (\set@display@protect). Macros are displayed inside ...

Top 50 recent answers are included