Tagged Questions
8
votes
2answers
58 views
Preserving (and Controlling) Expandedness
In most cases, by the time output gets to your screen, arguments are fully expanded and my question is moot. But sometimes (verbatim being a common example), one wishes to operate on arguments with ...
17
votes
2answers
226 views
Difficulty with macro expansion (updated)
I'm not getting the output I want from my LaTeX code, and I think the problem is that I'm not expanding things at the right times.
Code
\documentclass{article}
\usepackage{tikz}
...
7
votes
1answer
59 views
String Comparison with a \protected\def
I am using a \protected\def as that solved an earlier issue of mine. I need to compare this value of the token to see if it is initialized to the same value as the \protected\def in different ways.
...
2
votes
2answers
63 views
Undefined control sequence \pgfmath@
Why does the following code give me this error message?
Error
ERROR: Undefined control sequence.
--- TeX said ---
\pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@
l.28 \draw ...
4
votes
2answers
45 views
Package xparse \SplitList last token
I need to create a macro to render lists with a variable number of arguments (1+), e.g.
\mylist{1,2,3} should expand to $\tilde{1}$--$\tilde{2}$--$\tilde{3}$. I'm trying to use xparse and \SplitList, ...
9
votes
1answer
63 views
Expandable, very specific keyval processing
I am having a hard time trying to come up with an fully expandable keyval parsing macro which deals only with specific keys/values. I wouldn't even attempt this in full generality, that's way beyond ...
2
votes
1answer
78 views
Cutting string with formula or cite
I am trying to define a macro that would take a string and paint its ending, for example:
\def\paintString#1{%
\saveexploremode%
\exploregroups%
\textcolor{white}{\StrGobbleRight{#1}{5}}%
...
3
votes
2answers
59 views
How to append commands to a macro without expanding them
I'm working on building an expenses package. The intention is to be able to write
\expense{someone}{something}{something a bit longer}{10}{GBP}
\expense{someone else }{something else}{something a bit ...
3
votes
2answers
78 views
How to use a TeX macro with a CSV list to filter an external file
The code below produces the results I desire, which is a list of the lines with XXX={<value>} with a <value> which is not one of the allowed list of values:
However, this solution ...
4
votes
1answer
113 views
Preprocessing Latex: What is your workflow? Your tools?
I know, for various reason, some users preprocess their latex file using Perl or sed, say.
I'm considering doing this to, so I would like to seek your guidance, to smooth my entry in this area.
My ...
6
votes
2answers
108 views
Delaying command expansion that appears in \begin handler until \end handler executes
I have a custom environment for handling a code interface declaration that is specified as:
\begin{decl}{FOO}
\param{in}{bar} the bar input parameter
\param{out}{baz} the baz input parameter
...
12
votes
2answers
160 views
Expanding arguments before macro call
I've been banging my head against this for days. I have a macro which takes a macro name and its arguments. It then re-arranges the arguments a bit and then calls the passed macro with the re-arranged ...
10
votes
5answers
345 views
How to create a “delay expansion” environment?
I don't want to use the following
\begingroup
\edef\next{\endgroup
\noexpand\const{Xp}{\X(tp)}
\noexpand\const{Yp}{\Y(tp)}
\noexpand\const{Xf}{\X(tf)}
\noexpand\const{Yf}{\Y(tf)}
...
2
votes
1answer
39 views
Specify file name shell access via \@@input
Background:
I need to perform a conditional branch based on the first three characters of a file. I found a rather simple solution (on a Unix system, or PC with cygwin installed):
head -1 ...
14
votes
3answers
189 views
Parsing strings containing diacritical marks (macros?)
I apologize that this question may seem very much like several other recent ones I have asked (Parsing leading hardspaces, Parsing a \$ as part of an improved \getargs command). They are all related ...
5
votes
2answers
98 views
Variadic arguments macro
I am trying to make macro with variadic arguments, iterating over them.
The final result is supposed to be:
\foreach[x]((var = \x )){foo}{bar}{baz}\null
evals to
var = foo var = bar var = baz
My ...
6
votes
1answer
63 views
Forcing macro expansion with keyval
While trying to provide an answer to this question, I've run into a stumbling block that I can't seem to get over. The listings package (like many others) uses keyval to handle configuration. What ...
7
votes
2answers
105 views
Is there a way of defining a command \nullifyifmoved{arg} that will normally act like its argument but act like a no-op if the macro is “moved”?
I'm interested in a macro \nullifyifmoved that takes one argument arg and acts like arg in normal contexts, except it acts like a no-op wherever it is written to a file. Some background:
Martin ...
3
votes
1answer
54 views
List Version of \str_if_eq
I am using \str_if_eq:xxTF{\A}{\Target}{<true>}{<false} to execute the <true> or <false> code if \A=\Target.
What is the list version equivalent of this?
So I am looking for ...
9
votes
1answer
130 views
Is there a way of defining a command which is automatically converted to a no-op after its first execution?
Is there a way of defining a command that can be executed only once and is then redefined to be a no-op?
Related:
Is there a way of defining a command \nullifyifmoved{arg} that will normally act ...
5
votes
3answers
98 views
Metacommand for commands that dynamically select a parameter?
Original question
I would like to create a metacommand for creating new projection commands. Specifically, \newproj{\cmd}{<n>}{<m>} should create \cmd as a new command of <n> ...
5
votes
2answers
62 views
passing current content of commands to a macro
I am sorry for this is probably a current question with a well known answer, but I was not able to google it out.
I am trying to build a macro adding content step by step; at every step I need to ...
2
votes
1answer
90 views
Passing name ending with number to \csname does not work [duplicate]
Possible Duplicate:
macro names with special characters
When I use \yyy defined bellow it does not print yyy, but if I use \xxx it prints xxx. How can I make \yyy work?
\def\P1{yyy}
...
6
votes
1answer
215 views
Difference between \newcommand and \pgfmathsetmacro used in TikZ \coordinate
Consider the following code:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand{\MA}{4}
\pgfmathsetmacro{\MB}{4};
\coordinate (V11) at (0,0);
...
2
votes
1answer
129 views
Using “German” quotation marks inside \newcommand [duplicate]
Possible Duplicate:
babel shorthand "| doesn’t work in macros
I know there is a deeper non-understanding of LaTeX mechanics at work here, but I have no idea how to phrase my question ...
7
votes
1answer
126 views
\ifmmode self-contradictory in amsmath (OK in just LaTeX)
File:
\documentclass[11pt]{article}
\usepackage{amsmath}
\newcommand{\argghhh}{\relax\ifmmode\bar\else\expandafter\=\fi}
\begin{document}
$ \argghhh a $
\end{document}
produces error (but ...
2
votes
1answer
60 views
Pass the contents of an \input command to a macro
I am having some difficulty with the expansion of LaTeX. I would like to expand the contents of an \input command before passing them to macro, in a pattern similar to the following:
\outer{\inner}
...
8
votes
1answer
83 views
Omitting arguments in macro expansion
Changing a simple TeX macro like
\def\macro#1 #2{#1 #2}
into
\def\macro#1 #2{#1}
alters the output of
\macro Hello world
surprisingly for me to
Helloorld
My expectation would have been to ...
3
votes
1answer
54 views
how to return protected command with one argument already validated in latex/tex?
I want a command that will create an unevaluated bit of LaTeX/TeX code (to be evaluated at the end of an environment, but this is not necessary information) that has been created using an evaluated ...
3
votes
2answers
155 views
How to expand an argument defined with \csname…\endcsname?
Similar to the situation described in Expand after all that stuff?, I have a macro looking like
\somecommand{Some Argument}{\secondarg}.
I also need to expand the argument \secondarg before using ...
0
votes
2answers
75 views
suppress expansion in macro call
What I would like is to suppress the expansion of the group as a parameter to a macro so that it can be expanded later. For example we want to pass the paramater unmodified as a string to lua or to a ...
4
votes
2answers
157 views
Expand command and put result into a macro: Use of \value doesn't match its definition
I still struggle with the expansion of Latex. I try to calculate the a real number from a date format and put this into a macro \value. I need to expand the command with \edef because I plan to use ...
3
votes
1answer
111 views
Use macro to draw inside pgfplot/axis
I would like to implement a gantt chart function inside pgfplots. To draw the tasks, I have a macro that calculates the start and finish time of a task. However, when I use multiple tasks, the values ...
6
votes
1answer
82 views
Package providing fully expandable conditionals
Is there a package providing a collection of fully expandable conditionals like this one:
\newcommand\myif@num[1]
{\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
Background: ...
3
votes
2answers
128 views
Providing data series for sparkline environment
I would like to have the data series for a sparkline defined in terms of a macro -- or some alternative -- as opposed to have it set explicitly in the sparkline environment itself. My attempts so far ...
4
votes
3answers
85 views
Expanding an argument of code added by \g@addto@macro
I would like to have the following (it's a part of a large code block):
\def\C{foobar}
\def\A{}
\g@addto@macro\A{\B{\C}}
Now \show\A outputs \B{\C}
I would like to modify the 3rd line so that ...
35
votes
3answers
778 views
Advantages and disadvantages of fully expandable macros
As I currently understand them, fully-expandable macros are analogous to pure/effect-free functions in functional programming. Correspondingly, things that are not expandable, such as \def, are ...
9
votes
3answers
241 views
Implementing car and cdr in TeX
I've been trying to implement a macro that reads and transforms its argument into a different form...but I'm having quite a bit of trouble finding or creating even the most basic parsing tools.
Case ...
6
votes
3answers
281 views
Expandable string substitution
I am trying to define a macro
\formatstr{\mystring}{(string empty)}{the string is: #1}
which expands to (string empty) when \mystring is empty (as judged, e.g. by etoolbox's \csdefempty) and ...
22
votes
3answers
520 views
How to know whether or not we need \expandafter?
The following is quoted from Peter Grill's answer on question LaTeX dynamic macro definition.
The \expandafter is requried as the \newcommand needs to be dealt
with after the \csname.
As a ...
10
votes
3answers
220 views
Expandable 'character scanning' command that preserves spaces
David Carlisle recently offered a clean and rather elegant TeX solution to a question about expandable 'character scanning' commands. Unfortunately, David's solution does not preserve spaces in the ...
6
votes
1answer
110 views
On pitfalls of robust commands
These days, I’m more and more defining robust commands, e.g., using \newrobustcmd (etoolbox package) or \NewDocumentCommand (xparse package). Robust commands seem advantageous to me in many respects ...
42
votes
0answers
1k views
A LaTeX log analyzer application (visualizing TeX expansion)
Consider the following MWE, test.tex:
\documentclass[12pt]{article}
\begin{document}
\tracingassigns=1
\tracingmacros=1
\def\aaa{something}
\def\bbb{else \aaa, else}
\edef\ccc{third \bbb, level}
...
5
votes
1answer
245 views
A \typeout (or expandable command) that can expand once - or with variable levels of expansion?
Consider the following MWE:
\documentclass[12pt]{article}
\begin{document}
\def\aaa{something}
\typeout{=1==\aaa==}
\typeout{=1==\meaning\aaa==}
\typeout{}
\def\bbb{else \aaa, else}
...
6
votes
2answers
175 views
How to redefine commands and environments, and make them acceptable for `\write`
My general problem is the following. I want to "convert" many .tex files into some other format (xml-like). I don't want to modify the tex files, I can only build a documentclass.
The texfiles are ...
7
votes
1answer
224 views
Defining inside an \edef
The following throws an "Undefined control sequence" error:
\edef\testa{\edef\testb{foobar}\testb}
when it gets to expanding \testb.
This problem is also mentioned in "TEX by Topic" 12.6.2.
But no ...
18
votes
4answers
546 views
On testing two fully expanded character strings for equality
I know three macros that test two fully expanded character strings for equality:
\ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package)
...
2
votes
2answers
173 views
An expandable 'character scanning' command?
Please consider the following MWE, for a "character scanning" command "\looper" which utilizes \@tfor:
\documentclass{minimal}
\usepackage{trace}
\makeatletter
\newcommand\looper[1]{%
% ...
3
votes
1answer
129 views
Showing expanded `\let` command with `\typeout`
I have already seen the related page macros - What is the difference between \let and \edef?, but I'm afraid it still doesn't expain to me the following MWE:
\documentclass{minimal}
...
10
votes
4answers
254 views
Create a capitalized macro token using \csname
Two things I understand and one thing I don't:
I often use \csname to create user-defined tokens. For instance, the following code uses \expandafter to expand everything between \csname and ...

