When I iterate numbers with TikZ \foreach, they are stored in a macro. Now, when I need the letter corresponding to this macro, I can only convert it by saving it to a counter and then receiving it again.  \foreach \n in {1,...,10} {   \setcounter{number}{\n}   \edef\letter{\alph{number}} }   Directly issuing  \alph{\n}   does not work. I think it would be more efficient to avoid the counter. Is it possible convert directly?
122573
Here's basically what I try to do:  \begin{tikzpicture}   \foreach \x in {1,2,3,4,5}   {     \draw (\x,1) node{\Alph{\x}};   } \end{tikzpicture}   However if I do that, I get  ERROR: Missing number, treated as zero.   I tried to prefix the number with \the:  \begin{tikzpicture}   \foreach \x in {1,2,3,4,5}   {     \draw (\x,1) node{\Alph{\the\x}};   } \end{tikzpicture}   and got:  ERROR: You can't use `the character 1' after \the.   After searching around on TeX.SE, I thought the following solution should work:  \begin{tikzpicture}   \foreach \c [count=\x] in {{A},{B},{C},{D},{E}}   {     \draw (\x,1) node{\c};   } \end{tikzpicture}   However that got me an error that \x is not defined.  So, how do I get the desired result?
54515
I want to implement numbering scheme like Microsoft Word uses for numbering.  first one gets = A,next is  B, next is C, .... then AA, then AB,....and so on.  as shown below   A        B  C  .   .  AA  AB  AC  .  .  AAA  AAB  ....   '=>' here means converted to.  some examples:       1 =&gt; A 26 =&gt; Z 27 =&gt; AA 52 =&gt; AZ 53 =&gt; BA   and heres the code for it:     var convertToNumberingScheme = function(n){         var x = n-1,             r26 = x.toString(26),             baseCharCode = "A".charCodeAt(0);          var arr = r26.split(''),             len = arr.length;          var newArr =arr.map(function(val,i){             val = parseInt(val,26);              if( (i === 0) &amp;&amp; ( len &gt; 1)){                 val = val-1;             }              return String.fromCharCode(baseCharCode + val);         });         return newArr.join('');     }   It seems to work fine, but any ideas if there are some potential bugs or ways to  optimize this.
12927
I am trying to use \pgfmathsetmacro inside a foreach loop to connect nodes which are adjacent and named according to position as follows:  \foreach \src in {0,...,\T}{     \pgfmathsetmacro{\dest}{\src+1};     \path (n-\src-1) edge[&lt;-] (n-\dest-1); };   This however leads to the following error during compilation:  ./nn.tex:54: Package pgf Error: No shape named n-1 is known. [    }] ./nn.tex:54: Package pgf Error: No shape named n-2 is known. [    }] ./nn.tex:54: Package pgf Error: No shape named n-3 is known. [    }] ./nn.tex:54: Package pgf Error: No shape named n-4 is known. [    }]   which makes it seem as though the \dest value is not available. How do I get around this issue?  Thanks in advance!
78901
I want to change the letter-case of a single character argument, and use that changed letter inside a \csname.  And I want to do it without an additional package.  For example, I want to pass a macro the letter {S}, and have it execute the macro \csname macros\endcsname, or pass it the letter {T}, and have it execute the macro \csname macrot\endcsname.    In my MWE, I show three approaches:   I didn't expect \lowercase to work, since I recall reading that it is not truly expanded until the last possible moment.  Surprisingly, it goes into an \edef okay, but it must not be truly expanded, because it breaks the \csname. I also formulated an approach where I used \numexpr to add 32 to the ASCII code of the argument and perform a \char upon that result.  Like \lowercase, it gives the appearance of being expandable, but it also fails inside the \csname. I finally achieve success with the stringstrings package.  Having written the package, I know the conversion was not pretty... essentially, it is an exhaustive 26-fold check of the form \if #1Aa\else\if #1Bb\else\if #1Cc\else...\fi\fi\fi, which has the virtue that it can be expandably placed into an \edef, and so it works.   There has to be a better way.  The MWE works only because I use the inefficiently calculated \tmp from METHOD 3 inside the \csname.  If I use \tmp from either of the two earlier methods, it breaks.  \documentclass{article} \usepackage{stringstrings} \def\macros{Expandably converted an S to a s} \def\macrot{Expandably converted a T to a t} \newcommand\convert[1]{%   %MAKE THE ARGUMENT LOWER CASE   1) LOWERCASE\\   \edef\tmp{\lowercase{#1}}% PRETENDS TO EXPAND, BUT FAILS IN \csname   Here is the ``expanded'' conversion: \tmp\\   % OR   2) ASCII CONVERSION\\   \edef\tmp{\expandafter\char\numexpr`#1+32\relax}% PRETENDS TO EXPAND, BUT FAILS IN \csname   Here is the ``expanded'' conversion: \tmp\\   % OR   3) STRINGSTRINGS PACKAGE\\   \caselower[q]{#1}\def\tmp{\thestring}% WORKS BUT USES A PACKAGE   Here is the ``expanded'' conversion: \tmp\\   %   Now use it in a csname: \csname macro\tmp\endcsname% } \begin{document} \convert{S}\par \convert{T} \end{document}       SUMMARY OF ANSWERS:  I have added egreg's code snippets into this MWE to produce a document (and not just terminal output), showing the methods put forth to this point:  \documentclass{article}  %%%%%%%%%%%%%%%%%%%%%%%%%%%% L3 APPROACH  \usepackage{expl3}  \ExplSyntaxOn \cs_set_eq:NN \Xexplower \tl_expandable_lowercase:n \ExplSyntaxOff  %%%%%%%%%%%%%%%%%%%%%%%%%%%% EGREG'S LESS HACKY SOLUTION  \def\explowerchar#1{%   \ifcase\numexpr`#1-`A\relax    a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or m\or    n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z\else    #1\fi }  \def\explower#1{%   \doexplowerchar#1\relax }  \def\doexplowerchar#1{%   \ifx#1\relax   \else     \explowerchar{#1}\expandafter\doexplowerchar   \fi }  %%%%%%%%%%%%%%%%%%%%%%%%%%%% STEVE'S HACKY PACKAGE APPROACH  \usepackage{stringstrings}  %%%%%%%%%%%%%%%%%%%%%%%%%%%%  \def\macros{Expandably converted an S to a s} \def\macrot{Expandably converted a T to a t}  \begin{document}  \textbf{Steve's hacky approach}  \caselower[q]{S}\csname macro\thestring\endcsname\par \caselower[q]{T}\csname macro\thestring\endcsname  \textbf{egreg's less hacky approach}  \edef\lcstring{\explowerchar{S}}\csname macro\lcstring\endcsname\par \edef\lcstring{\explower{T}}\csname macro\lcstring\endcsname  \textbf{L3 approach}  \edef\lcstring{\Xexplower{S}}\csname macro\lcstring\endcsname\par \edef\lcstring{\Xexplower{T}}\csname macro\lcstring\endcsname  \end{document}
73111
In my macro file, I have certain theorem environments defined, for example.  \newtheorem{theorem}{Theorem} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{corollary}[theorem]{Corollary}  \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition}   Again, these lines are in my macros.sty file of shortcuts.  In the past, I have changed the numbering of theorem, etc... by using \numberwithin. I have recently learned that I can instead edit the \newtheorem line. For example, if I want results numbered according to section I can use  \newtheorem{theorem}{Theorem}[section]   My question now is about future situations when I have two documents, which both use the same macros.sty file, but in one document I want to number results by section and in the other document I want to number results by something else, say chapter.  How can I accomplish this without creating two different .sty files?   EDIT: I think I should add that I am looking for a way to do this without going back to \numberwithin. The reason for this is because \numberwithin doesn't seem to work well with the thmtools package.
26339
Is there some rare language construct I haven't encountered (like the few I've learned recently, some on Stack Overflow) in C# to get a value representing the current iteration of a foreach loop?  For instance, I currently do something like this depending on the circumstances:  int i = 0; foreach (Object o in collection) {     // ...     i++; }
39710
Is it possible to create a counter that is a "slave" to another (master) counter, but also an exact duplicate?  The \@addtoreset{&lt;slave&gt;}{&lt;master&gt;} resets &lt;slave&gt; whenever &lt;master&gt; is incremented (similar functionality is offered by ), but I don't know about anything incrementing one counter (&lt;slave&gt;) automatically whenever another counter (&lt;master&gt;) is incremented.  The idea is to have a macro (say) \dupcntr{&lt;slave&gt;}{&lt;master&gt;} as an analogue to \@addtoreset. The application for this might be where one is interested in renaming a counter used/provided by a package into something more meaningful for the user (say, &lt;slave&gt;), without having to reference &lt;master&gt;. Or, if the original counter contains @ that needs to be escaped every time it's used, it is sometimes more convenient to have a "more user friendly" counter.  I know one way around is to use a macro that returns the value of &lt;master&gt;, but is it possible to perform the same manipulation with a macro than one could with the counter? Manipulation here refers to the printing of the counter (via \the&lt;slave&gt;) and perhaps it's representation (like \arabic, \alph, ...).
72095
I would like to copy the row of a table, let say, n times, but unfortunately my sample below does not compile. It is my understanding that the \foreach command should copy what is in its argument but is not doing it here. I have looked at the error message in the compiler and I have an idea as to what may be causing it. I think it is how the table environment is constructed. I am thinking right now of enveloping the command as a group but I don't know how to do this. What is the best way to achieve this result? Some explanation will be appreciated.  \documentclass[letterpaper]{article} \usepackage{amsmath,amssymb,lipsum} \usepackage{tikz,calc} \newcommand{\test}[1]{%     \foreach \i in {1,...,#1}     {%     t1 &amp; t2 \\%     }} \begin{document} \begin{tabular}{cc} \test{3} \end{tabular} \end{document}
31396
I want to draw a bunch of nodes with different styles (a, b, ...) at different points (named 00, 01, ...). I am using the following code:  \foreach \n/\lst in {   a/{00, 14, 20, 34},   b/{01, 11, 23, 33} } {   \foreach \xy in \lst {     \node[\n] at (\xy) {\n};   } }   with the hope that \lst would be assigned a list, and \xy would be assigned elements from this list. However, I get error Package pgf Error: No shape named {01, 11, 23, 33}  is known. How to fix this?
28318
I'm trying to format numbers. Examples:  1     =&gt; 1 12    =&gt; 12 123   =&gt; 123 1234  =&gt; 1,234 12345 =&gt; 12,345   It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.  Edit: If you've a generic Python way to do this, I'm happy adding a formatted field in my model.
71740
In my previous question, , I was suggested using a foreach loop to solve the problem. After testing, the loop works correctly as show in page 1 pdf. However, when more FENs are added, loop gives wrong format as shown in pdf 2 and 3. Any suggestion on how to fix the foreach loop is appreciated.   \documentclass{article} \usepackage{xskak,chessboard} \usepackage[margin=3cm]{geometry} \begin{document}  %**** WORKSHEET 1 IS CORRECT; WORKSHEET 2 AND 3 IS WRONG ****** %******************************************************** %******CORRECT WORKSHEET USING FOREACH LOOP *******  \foreach \X/\Y in  {basic/{3k4/8/2Q5/4K3/8/8/8/8 w - - 0 1, 8/8/2k5/7R/6R1/8/5K2/8 w - - 0 1, 1k6/7R/3K4/8/8/8/8/8 w - - 0 1}, %******* PAWN LEVEL ***************** pawn/{8/8/8/8/8/1k6/7P/4K3 w - - 0 1, 8/8/8/8/4k3/4p3/4K3/8 w - - 0 1, 8/1k6/8/8/1PK5/8/8/8 w - - 0 1}, %************ 2 PAWN LEVEL ******************* 2 pawns/{8/8/8/4p1K1/2k1P3/8/8/8 w - - 0 1, 8/8/8/p7/P7/7k/7P/6K1 w - - 0 1, k7/P1K5/6p1/7p/7P/8/8/8 w - - 0 1}, %************ MINOR + PAWN LEVEL ******************** Minor + Pawns/{4BK2/6P1/5k2/8/8/1b6/8/8 w - - 0 1,  8/8/4k3/2p4n/2P1K3/8/7B/8 w - - 0 1, 8/p7/P5p1/1P4P1/5P2/3kb3/8/3K4 w - - 0 1}} {\noindent\tikz{\node[rotate=90,font=\bfseries,align=center,text width=4cm]{\X};} \foreach \Z in \Y {\begin{minipage}[b]{0.35\linewidth} \chessboard[smallboard,setfen=\Z] \end{minipage}}  } %****** WHEN NEW FENS ARE ADDED, FOREACH LOOP GETS WRONG. WORKSHEET IS NOT SAME AS ** %**** PREVIOUS WORKSHEET ***** \foreach \X/\Y in  {basic/{3k4/8/2Q5/4K3/8/8/8/8 w - - 0 1, 8/8/2k5/7R/6R1/8/5K2/8 w - - 0 1, 1k6/7R/3K4/8/8/8/8/8 w - - 0 1}, basic/{3k4/8/2Q5/4K3/8/8/8/8 w - - 0 1, 8/8/2k5/7R/6R1/8/5K2/8 w - - 0 1, 1k6/7R/3K4/8/8/8/8/8 w - - 0 1}, %******* PAWN LEVEL ***************** pawn/{8/8/8/8/8/1k6/7P/4K3 w - - 0 1, 8/8/8/8/4k3/4p3/4K3/8 w - - 0 1, 8/1k6/8/8/1PK5/8/8/8 w - - 0 1}, pawn/{8/8/8/8/8/1k6/7P/4K3 w - - 0 1, 8/8/8/8/4k3/4p3/4K3/8 w - - 0 1, 8/1k6/8/8/1PK5/8/8/8 w - - 0 1}, %************ 2 PAWN LEVEL ******************* 2 pawns/{8/8/8/4p1K1/2k1P3/8/8/8 w - - 0 1, 8/8/8/p7/P7/7k/7P/6K1 w - - 0 1, k7/P1K5/6p1/7p/7P/8/8/8 w - - 0 1}, 2 pawns/{8/8/8/4p1K1/2k1P3/8/8/8 w - - 0 1, 8/8/8/p7/P7/7k/7P/6K1 w - - 0 1, k7/P1K5/6p1/7p/7P/8/8/8 w - - 0 1}, %************ MINOR + PAWN LEVEL ******************** Minor + Pawns/{4BK2/6P1/5k2/8/8/1b6/8/8 w - - 0 1, 8/8/4k3/2p4n/2P1K3/8/7B/8 w - - 0 1, 8/p7/P5p1/1P4P1/5P2/3kb3/8/3K4 w - - 0 1}, Minor + Pawns/{4BK2/6P1/5k2/8/8/1b6/8/8 w - - 0 1, 8/8/4k3/2p4n/2P1K3/8/7B/8 w - - 0 1, 8/p7/P5p1/1P4P1/5P2/3kb3/8/3K4 w - - 0 1}} {\noindent\tikz{\node[rotate=90,font=\bfseries,align=center,text width=4cm]{\X};} \foreach \Z in \Y {\begin{minipage}[b]{0.35\linewidth} \chessboard[smallboard,setfen=\Z] \end{minipage}} \par } \end{document}
115741
I'm trying to draw some repeated with PGF/Tikz, and I'm using a foreach. Problem: each line has, on the right, a description, which is a string of text - which may be somewhat long and contain commas or math expressions.  How can I create a list of strings, iterating over it and use each string as node text?
6626
I have defined a new counter that keeps increasing each time I call the macro that's using it. How can I print the counter value minus one? Something like \value{\theCounter-1} but formatted for text?  MWE  \documentclass{article} \usepackage{parskip} \newcounter{myCount} \setcounter{myCount}{1} \newcommand\newSec[1]{\par\underline{\textsc{newSec}~\themyCount}\hspace{0.5em}{\footnotesize(#1~number)}\stepcounter{myCount}\par}  \begin{document}     \newSec{2}     Some text      \newSec{5}     Here I refer to the counter used before it was incremented: \themyCount. Should print 2.  \end{document}
110146
Based on this question:  I got some nice tools for illustrating to my students how to find the product of a number or a variable and a parenthesis.   However, the solution fails when I should have two sources in one line, for instance when expanding (a+3)(b+4). I would also be able to place a small number next to or above the arrowhead to indicate the first calculation, the second, etc. The second set of arrows could just as well go below the expression, not above it, to simplify things.   I could of course define myself a new set of macros similar to the existing ones, for instance \sourceTwo and \targetTwo, but it feels like this could be done more elegant.   MWE:  \documentclass[]{article} \usepackage[utf8]{inputenc} \usepackage{tikz}  \newcommand\source[1]{%     \tikz[remember picture,baseline,inner sep=0pt] {%         \node [name=source,anchor=base]{$#1$};     }%     \setcounter{target}{0} } \newcounter{target} \newcommand\target[1]{%     \tikz[remember picture,baseline,inner sep=0pt] {%         \node [name=target-\thetarget,anchor=base]{$#1$};     }%     \stepcounter{target}% } \newcommand\drawarrows{     \tikz[remember picture, overlay, bend left=45, -latex] {         \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {             \draw (source.north) to (target-\n.north);         }     } }  \begin{document}  \begin{equation}     (\source{a}+4)(\target{b}+\target{3}) = \drawarrows \end{equation}  \end{document}
53423
I am trying to build a table, and inside the tabularx environment I would like to have a loop, something like (here is a MWE):  \documentclass[10pt,a4paper]{article} \usepackage{tabularx} \usepackage{tikz} \newcommand{\nRows}{5} \begin{document}   \begin{tabularx}{\textwidth}{@{}&gt;{\raggedright}p{2.2cm}@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}}     \foreach \r in {1,...,\nRows}{  % https://stackoverflow.com/questions/2561791/iteration-in-latex         \textbf{column1} &amp; two &amp; three &amp; four &amp; five      } \end{tabularx}  \end{document}   This doesn't work, because the ampersands (&amp;) are causing problems. If I escape the &amp;s, then the entire line gets printed in the first column, along with the literal ampersands, kind of like:  \documentclass[10pt,a4paper]{article} \usepackage{tabularx} \usepackage{tikz} \newcommand{\nRows}{5} \begin{document}   \begin{tabularx}{\textwidth}{@{}&gt;{\raggedright}p{2.2cm}@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}}     \foreach \r in {1,...,\nRows}{  % https://stackoverflow.com/questions/2561791/iteration-in-latex         \textbf{column1} \&amp; two \&amp; three \&amp; four \&amp; five      } \end{tabularx}  \end{document}   This yields:  |column1 &amp;      | | | | | two &amp; three &amp; | | | | | four &amp; five   | | | |   Whereas what I want is:  |column 1 | two | three | four | five | |column 1 | two | three | four | five | |column 1 | two | three | four | five |   ....  Any ideas on how I can achieve this? I'm actually NOT looking to make identical rows - the rows will be different. This is just a MWE. Thanks!  Edit: I have tried implementing Herbert's answer as recommended in the comments section. It results in no output - just a blank PDF. Here is how I implemented it:  \documentclass[10pt,a4paper]{article} \usepackage{tabularx} \usepackage{tikz} \newcommand{\nRows}{5}  \makeatletter \newtoks\@tabtoks \newcommand\addtabtoks[1]{\@tabtoks\expandafter{\the\@tabtoks#1}} \newcommand*\resettabtoks{\@tabtoks{}} \newcommand*\printtabtoks{\the\@tabtoks} \makeatother  \begin{document}      \resettabtoks     \foreach \r in {1,...,\nRows}{  % https://stackoverflow.com/questions/2561791/iteration-in-latex         % \textbf{column1} \&amp; two \&amp; three \&amp; four \&amp; five          \addtabtoks{\textbf{column1} &amp; two &amp; three &amp; four &amp; five \\\hline}%     }  \begin{tabularx}{\textwidth}{@{}&gt;{\raggedright}p{2.2cm}@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}&gt;{\raggedright}X@{}} \printtabtoks \end{tabularx}  \end{document}   Any ideas on what I am doing wrong? Thanks!
44869
I would like to create some name badges using a loop. I have a spreadsheet with names and affiliations that I save in names.csv file as follows  "Name1","Surname1","Affiliation1", "Name2","Surname2","Affiliation2", "Name3","Surname3","Affiliation3"   I can copy the content of names.csv in a string array and use a loop to recover the entries. The following is an example of working code producing the output Surname2:    \documentclass{article} \usepackage{tikz} \usepackage{pgf} \usepackage{array}  \def\names{{"Name1","Surname1","Affiliation1", "Name2","Surname2","Affiliation2", "Name3","Surname3","Affiliation3"}}  \begin{document}  \pgfmathparse{\names[4]}\pgfmathresult  \end{document}   I can use this idea to create hundreds of name badges in a loop. But instead of writing the whole list in the .tex file I would like to call directly my names.csv file. I used the modified code  \documentclass{article} \usepackage{tikz} \usepackage{pgf} \usepackage{array}  \def\names{{\input{names.csv}}}  \begin{document}  \pgfmathparse{\names[4]}\pgfmathresult  \end{document}   which apparently enters in an endless loop. I understood that \input{} works just as copy-pastying, but it doesn't seem the case. Of course I can work in the spreadsheet and then copy paste the names.csv file content, but I would like to understand what happens. Any clues?  PS edit: The suggested solution is enough for my case. But still I would like to be able to define macros with \input'. It seems that\input{}' inside a macro is not expanded immediately. I mean if I have some code in file.tex', that I want to plugin in a new macro,\def\mymacro{\input{file}}' will save \mymacro' as '\input{file}' and will only look what's inside the file when I call the macro in the document. That's why in the previous example\names' is not understood as an array. In the same way  \begin{filecontent*}{newfile.tex} \input{file} \end{filecontent*}   will save the code \input{file}' innewfile.tex', but not the content in `file.tex'. Anyone has any idea how to force input to expand?
107901
The \show command is extremely useful for figuring out what's going on with a particular macro.  Similarly, using \the can tell me the value of a counter.  I'd like to know if there's something similar for lengths and skips.  At the moment, I end up doing something like \rule{1pt}{\unknownlength} but that's a fairly crude method.