# Tag Info

12

You're better served with expl3: \documentclass{article} \usepackage{amsmath,amssymb} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\makeabbrev}{mmm} { \yoruk_makeabbrev:nnn { #1 } { #2 } { #3 } } \cs_new_protected:Npn \yoruk_makeabbrev:nnn #1 #2 #3 { \clist_map_inline:nn { #3 } { \cs_new_protected:cpn { #2 } { #1 { ##1 } } } } \...

12

You need to expand and let LaTeX know that you mean a control sequence \documentclass{article} \usepackage{amssymb} \usepackage{pgffor} \foreach \x in {C,N,Q,Z,D,R,T}{\expandafter\xdef\csname\x\x\endcsname{\noexpand\mathbb{\x}}} \begin{document} \foreach \x in {C,N,Q,Z,D,R,T}{$\csname\x\x\endcsname$} \end{document}

10

TikZ doesn't solve x+md<z equation to come up with the proper m or d for that matter. It starts adding \isecond - \istart amount in this case 2 after(!) evaluating the loop at \istart and \isecond because those points are given. Then checks whether 1+2 < -1 no then quits with I'm done. You can use \ifodd, \ifeven if clauses if you want to branch off ...

10

I propose a different definition of \current@item \def\current@item#1{% \stepcounter{item@count} \item $|$#1$|$\ $|$\texttt{\detokenize{#1}}$|$% } so the output also shows what's really passed as its argument. Also I changed the complicated management of \my@item@count with a simple counter. I don't comment about \@tfor, which is a different tool not ...

9

As mentioned in the comments it is more efficient to avoid \foreach and do your own tests for empty lists or list items. Also anything done within a \foreach iteration has to be done globally to last past the end of the loop. There may be packages which already provide this functionality but here is an example of what could be done. It contains a bit more ...

9

Please post compilable or at least copy/pastable code so that we can see what you want to do. Until then \documentclass{article} \usepackage{pgffor} \begin{document} \foreach \x[evaluate=\x as \evalx using int(\x*(\x+1)/2)] in {1,...,10}{ \texttt{Something you want : \evalx} } \end{document}

9

0.1 in binary has infinite representation. See, for instance, Why 0.1 Does Not Exist In Floating-Point? So there will be rounding errors. Also, as @DavidCarlisle pointed out in the comment, TeX is good at integer arithmetic, which adds another layer of error. \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[scale=16] \foreach \...

8

Each cycle of \pgffor is performed in a group, so the definition of the toggles and the setting don't survive them. One can solve the issue with \toggletrue by writing \global\toggletrue, but there's no “global \providetoggle”. However you can define your own: \let\gprovidetoggle\providetoggle \patchcmd{\gprovidetoggle}{\cslet}{\global\cslet}{}{} Example: ...

8

You can use etoolbox and its \ifboolexpr command to combine several conditionals of the form \<conditional [possibly with additional arguments]>{<true>}{<false>} into one. Note the test keyword in front of each conditional and the braces around them. \documentclass{article} \usepackage{etoolbox} \newcommand{\test}{} % just to make sure \...

7

Finally got it. After perusing the links suggested by @percusse I finally found the right combination of \expandonce and \noexpand commands to build the contents of a tabular environment within a pgffor \foreach loop. Here's the working MWE: \documentclass{article} \usepackage{pgfkeys} \usepackage{pgffor} \usepackage{etoolbox} \makeatletter \def\ae@col@...

7

The issue is expansion here. \ifx tests whether the two following macros (if macros are passed) have the same meaning. In the first case \temparg has the meaning macro:->\myvar, whereas \vala has the meaning macro:->aa and \valb is macro:->bb. Your \myvar has macro:->\vala and macro:->\valb as meaning in your loop. If you expand it twice ...

6

You don't want to only escape /None, but also # that's illegal in that context: \edef\hms{\string#/}% Hash Mark Slash \foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf -dAutoRotatePages\hms None/ps} {\immediate\write18{\compiler\space frames.\ext}} The variant you mentioned in chat is even better: \edef\AutoRotateOff{-dAutoRotatePages\string#/...

6

Enrico Gregorio has already explained the reason in his comment: \foreach puts the body of its loop in a group. That conflicts with the cell grouping of the matrix environment. Another problem, if there is something after the line end that is not expandable (end of group, \relax, ...), then a new (empty) line is created. The following uses the loop to ...

6

As @herbert already explained in his answer, ; and other characters are active in french. This is conflicting with TikZ, which is using ; to end a drawing command. To resolve the issue, one can use the tikzlibrary babel, which isnt doing more than \tikzset{ handle active characters in code, handle active characters in nodes } Now, you can still use ...

6

The problem is the endline automatically implied at the end of input files. I removed all you spurious spaces to make the output clearer. \begin{filecontents*}{\jobname1.dat} 1,2,3 \end{filecontents*} \begin{filecontents*}{\jobname2.dat} {1,0,2},{0,3},{1,1} \end{filecontents*} \documentclass{article} \usepackage{catchfile} \usepackage{pgffor} \...

6

Unless I misunderstand your question, you don't need the \renewcommand macros or \foreach loop. You can also randomly change the operator mid way through the document. \documentclass{article} \usepackage{fdsymbol} \usepackage{pgf} \pgfmathsetseed{\number\pdfrandomseed} \pgfmathdeclarerandomlist{choices}{{\medtriangleright}{\pm}{+}{\cdot}} \begin{document} \...

6


6

This makes use of TikZ's mod and floor operators: %\documentclass[export]{standalone} % for multipage PDF/animated GIF \documentclass{article} \usepackage{tikz} \usepackage{animate} \begin{document} \begin{animateinline}[poster=first, controls] {20} \multiframe{100}{ii=0+1,rj=9.9+-0.1}{% ii=0,1,...99 ; rj=9.9,9.8,...,0.0 % \pgfmathsetmacro{\Rx}{mod(\...

5

Since PGF and PGFPlots are getting married to Lua as well, here is another example in LuaLaTeX. \documentclass{article} \begin{document} \directlua{ for n = 1,10 do tex.sprint(n*(n+1)/2 ..', ') end } \end{document}

5

The problem is that \foreach is evaluated in a group to prevent overwriting of the contents of the iteration variable. TeX does not allow alignment tabs to grouped in alignments, hence the error. You could use \pgfplotsforeachungrouped from the pgfplots package to circumvent that restriction. Also you might want to have a look at the formatting again. ...

5

Here are two solutions: \documentclass{article} \usepackage{pgfkeys} \usepackage{pgffor} \pgfkeys{ /list1/.initial = {1,2,3}, % /list2/.store in=\mylisttwo, /list2={1,2,3}, } \begin{document} \pgfkeys{body loop/.code={A = #1\par},body loop/.list/.expanded=\pgfkeysvalueof{/list1}} \pgfkeys{/list1={a,b,c}} \pgfkeys{body loop/.code={A = #1\par},body ...

5

I get a different error once the forloop package is added: ! Misplaced \noalign. \hline ->\noalign {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet... l.19 ...lines}{1}{\value{theyflines} < 20}{\hline} \\ This is the error that happens when you don't insert a tabular new ...

5

As Henri said in the comment, the \foreach loop is grouped, so it isn't really fit for this type of application. You can use expl3's \seq_use:Nn <seq var> {<thing>} to add <thing> between each item of <seq var>: \documentclass{article} \usepackage{amsmath,xparse} \ExplSyntaxOn \seq_new:N \l_trevion_tmp_seq \NewDocumentCommand \Hor {...

5


5

The syntax of \@ifclassloaded is \@ifclassloaded{class}{yes code}{no code} so you do not need \else. Both branches are built in to the syntax. You have \@ifclassloaded{book} {% <code block> } \makeatother% so your "no code" argument is \makeatother so you only execute that if the class is not book. You should never have \makeatletter or \...

5

There is a difference in how check (\defbibcheck) and the type option filter bibliographies. With type (and similarly with keyword, category, segment) biblatex can tell from the start whether or not the bibliography will be empty. This is not possible with check. So one solution would be to try and base your filtering on bibliography categories. With some ...

4

A more flexible solution with fp just for fun. My example below uses an extreme case which is f(x)=sin(x*π/10) instead of your simple case which is f(x)=x*(x+1)/2. \documentclass[preview,border=12pt,12pt,varwidth]{standalone} \usepackage{pgffor} \usepackage[nomessages]{fp} %\def\f[#1]{#1*(#1+1)/2}% f:x --> x*(x+1)/2 \def\f[#1]{sin(#1*pi/10)}% XTreme ...

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