Tag Info

Hot answers tagged

6

A modification of my answer at http://tex.stackexchange.com/a/213027/4427 \documentclass{article} \usepackage{xparse,siunitx} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\convertdim}{O{2}mm} { \fp_eval:n { round ( \dim_to_decimal_in_unit:nn { #2 } { 1#3 } , #1 ) } } \ExplSyntaxOff \NewDocumentCommand{\getlengthin}{O{2}mm} {% ...


6

OK, I think I see what's happening. When I define \aetest \newcommand\aetest[2][\relax]{%% \def\aejunk{<#2>}%% \ifx\relax#1 \else \def\aejunk{(#2:#1)}%% \fi \fbox{\aejunk\rule[-0.5ex]{0pt}{2.5ex}}%% } There is, as of yet, no expansion of #1 or #2 yet to happen. So, when \aetest is defined, the end of line character after #1 gets ...


6

When TeX is absorbing the replacement text for a definition, it does no expansion whatsoever (unless you're using \edef or \xdef). In your replacement text you have \ifx\relax#1 and the end of line counts as a space, because it is converted to a space during tokenization since it doesn't follow a control word. The space will not be ignored during ...


6

#1 is a delimited argument that consists of all tokens up to the specified delimiter, \separator here. LaTeX doesn't really support the definition of such arguments (hence the use of \def rather than \newcommand. #2 is a normal non-delimited argument. So this takes a single token or {} group. In the case you trace it just gets T just as if you go \fbox ...


5

Expanding macros inside a sagesilent requires changing the catcode treatment within the environment. The code below will create a sagesilentexp environment in which macros are expanded. Macros will behave a little differently than normal. A macro that doesn't take arguments won't eat trailing spaces, because the spaces are now literal. If a macro that ...


4

The four values for options viewport or trim are identified by the separating spaces. The parser, defined for these options by package graphicx expects explicit spaces and fails, if the spaces are hidden inside a macro. The following example redefines option viewport (in the same way option trim can be redefined) to expand its argument before passing the ...


3

Here's a way to do this: 8.50 in 193.30 mm 19.3 cm \documentclass{article} \usepackage{siunitx} \ExplSyntaxOn \cs_new_eq:NN \calc \fp_eval:n \ExplSyntaxOff \makeatletter \newcommand{\getlengthin}[3][]{% \setlength{\@tempdima}{#2}% Capture length \setlength{\@tempdimb}{1 #3}% Capture unit \SI[round-mode=places,round-precision=2,#1] ...


3

Here are a couple of ways: \documentclass{article} \usepackage{graphicx} \newcommand{\myviewport}{viewport=0pt 10pt 200pt 50pt} \begin{document} \includegraphics[clip, viewport=0pt 10pt 200pt 50pt]{example-image} \begingroup\edef\x{\endgroup\noexpand\includegraphics[clip, \myviewport]{example-image}}\x ...


3

You can define a new key for \includegraphics, I'll call it xviewport. \documentclass{article} \usepackage{graphicx} \usepackage{calc} \makeatletter \define@key{Gin}{xviewport}[]{% \begingroup\edef\x{% \endgroup\noexpand\setkeys{Gin}{viewport=\x@viewport}% }\x } \newlength{\Xoffset} \newlength{\Yoffset} \newcommand*{\setpdfoffset}[2]{% ...


3

You have to expand the row number as far as you can before adding it to the \tablines token list. Here's one way of achieving that: \documentclass{article} \newcounter{it} \newcounter{tot} \newtoks\tablines \newcommand{\addtomytablines}[1]{\tablines\expandafter{\the\tablines#1}} \setcounter{it}{2} \setcounter{tot}{7} \loop ...


2

You can do this with two counters, one inside the \addtomytablines command, and one for the main loop. (I don't fully understand why.) I took the liberty of cleaning up your code and writing it in LaTeX. \documentclass{article} \newtoks\tablines \def\addtomytablines#1{\tablines\expandafter{\the\tablines#1}} \newcounter{row} \newcounter{loop} ...


2

This works, but may not be general enough for your need: \documentclass{article} \usepackage[demo]{graphicx} \begin{document} \newcommand*{\aport}{45.29pt 86.28pt 235pt 187pt} \def\X{\includegraphics[clip, viewport=} \expandafter\X\aport]{somepdf.pdf} \end{document}


1

Since I was playing around with it 9 months after I asked the question, and developed a different approach, I will post it here. It achieves the result by making upper- or lower-cased characters active and then redefining them in the other lettercase. It achieves the goal of the question, which was "I want to pass a macro the letter {S}, and have it ...



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