0

I want to build commands to write the ToC of a paper. In my MWE the solution 1 works, but I do prefer the solution 2, which is not working. How can I make it work?

\documentclass{article}

\usepackage{tikz}

\newcommand{\ssxa}{test 1}
\newcommand{\ssxb}{test 2}


\begin{document}
% First solution 
\foreach \i in {\ssxa,\ssxb}{%
    \section{\i}
}
% Second solution (does not work)
\foreach \i in {a,b}{
    \edef\j{\expandafter\csname ssx\endcsname\i}
    \section{\j}
}
\end{document}
  • 1
    \def\j{\csname ssx\i\endcsname} – David Carlisle Oct 10 '16 at 23:20
1
\documentclass{article}

\usepackage{tikz}

\newcommand{\ssxa}{test 1}
\newcommand{\ssxb}{test 2}


\begin{document}
% First solution 
\foreach \i in {\ssxa,\ssxb}{%
    \section{\i}
}
% Second solution (does not work)
\foreach \i in {a,b}{
    \section{\csname ssx\i\endcsname}
}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.