Hot answers tagged

8

The primitive \expandafter carries out exactly one expansion and leaves the result of this in the input stream. Thus \expandafter\def\csname #1\endcsname with #1 as foo is equivalent after one expansion to \def\foo To get things correct, you have to track how many expansions are required and to know the number of \expandafter commands you need (1, 3, 7,...


6

Appending to an existing (parameterless) macro only requires one chain: \expandafter\def\expandafter\foo\expandafter{\foo<material to add>} If the parameterless macro is called by name, so requiring \csname, the problem is a bit more complicated, requiring seven \expandafter tokens scattered in various places. You can do it more easily with various ...


3

Two examples that you could use \ExplSyntaxOn \tl_new:N \g_florian_whatever_tl \NewDocumentCommand \setbegdoctext { m } { \tl_gset:Nn \g_florian_whatever_tl { #1 } } \NewDocumentCommand \printifwhatever { } { \bool_if:NT \g_florian_whatever_bool { \tl_use:N \g_florian_whatever_tl } } \ExplSyntaxOff \AtBeginDocument{\printifwhatever} \setbegdoctext{...


2

It works fine using piped input instead: \documentclass{article} \usepackage{datetime2} \begin{document} \def\mydate{2015-01-01}% \def\mytime{12:23}% \def\offset{-7} \makeatletter \begingroup\endlinechar=-1\relax \edef\pc{\expandafter\@gobble\string\%} \everyeof{\noexpand}% \edef\x{\endgroup\def\noexpand\ScriptResult{% \@@input|"echo '\mydate\space\...


2

You don't give much to go on, but this plain tex file shows the described behaviour, the first call works, the second gives an error. \def\func#1{\expandafter\string#1} \def\head{\titel } % \titel = undefined \func{\head} % func is defined and handles \titel without any issues \func{\titel} \bye


2

I think it's difficult to understand the question, it's just too cryptic until one understands it :) I'm going to try to answer this in a constructive way. Your problem is \g@addto@macro{\trackedmacro}{^^J==> #1 (\contextinfo)} that doesn't expand the \contextinfo, so in the end you have \contextinfo .. \contextinfo .. \contextinfo .. \contextinfo all ...


2

Try this, but I don't know whether this is the correct result. In my opinion, the \tracklistmacro should be recursively defined within \section then. \listfiles \documentclass{article} \usepackage{atveryend} \usepackage{currfile}% adds \currfilepath % Define a couple commands to track \DeclareRobustCommand{\myapp}[1]{\textit{#1}} \DeclareRobustCommand{\...


2

you want to add the expansion of \i not the token \i so \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{pgffor} \makeatletter \newtoks\@tabtoks \newcommand\addtabtoks[1]{\global\@tabtoks\expandafter{\the\@tabtoks#1}} \newcommand*\resettabtoks{\global\@tabtoks{}} \newcommand*\printtabtoks{\the\@tabtoks} \makeatother \begin{document} \...


1

The difference is because you aren't expanding \itemnum when passing it to \cmdwithexpandedargs, but \wlog fully expands its argument. You can do it more efficiently: \documentclass{letter} \newcounter{nenv} \newcommand\printcmd{} \makeatletter \newenvironment{test}{% \stepcounter{nenv}% \let\olditem\item \renewcommand\item{% \olditem ...


1

With the updated code in http://tex.stackexchange.com/a/165149/4035 you can do \documentclass[10pt,a4paper]{article} \usepackage{pgffor} \makeatletter \newtoks\@tabtoks %%% assignments to \@tabtoks must be global, because they are done in \foreach \newcommand\addtabtoks[2][]{% \if\relax\detokenize{#1}\relax % no index, just append the second argument ...


1

\expandafter\addtabtoks\expandafter{\i & \i\\\hline} only expands the first \i so you are adding 1&\i then 2&\i then 3&\i so the second column gets the same value at each iteration. You could use \edef\x{\noexpand\addtabtoks{\i & \i\noexpand\\ \noexpand\hline}} \x To fully expand both instances of \i before adding to the token ...



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