4
votes
5answers
172 views

macros, category codes, how to pass stuff with cat codes inside?

The original question is below (it was a bad simplification of the problem I had and also before being edited, it also contained major syntax errors). The problem that originated the question is why ...
5
votes
1answer
72 views

TikZ programming/macros, \list construct

TikZ 3.0 manual, on page 83, we have (not complete code): \list{--}{\topsep=2pt\itemsep=0pt\parsep=0pt \parskip=0pt\labelwidth=8pt\leftmargin=8pt \itemindent=0pt\labelsep=2pt} #5 ...
4
votes
0answers
35 views

Is there a good reason to define helper macros second? [duplicate]

As a mathematician, my training is to define my terms before I use them. As a computer programmer, I recognize that there are sometimes good reasons to call a method/function/procedure before its full ...
7
votes
1answer
106 views

Make the pattern of a \def depend on another macro

I would like to set up a macro defined something like this: \def\processline string: #1.#2\relax{\gdef\errorline{#1}} The catch is that the string should be given by the contents of another macro. ...
5
votes
1answer
197 views

Creating a simple list of symbols

Inspired by this great answer I tried to manually create a glossary-style environment for a simple list of symbols. Basically I wanted to create a command newsymbol that can be executed from anywhere ...
10
votes
0answers
98 views

create list of thumbnails for each section [closed]

I want to create a cooking book. There I want to define for each receipe a thumbnail image. At the beginning of each chapter I want to show instead of a TOC a gallery of thumbnails of each subsection ...
0
votes
0answers
80 views

I need some help debugging this LaTeX macro - TeX “skips past” a bunch of code?

I'm trying to test and debug a collection of LaTeX macros that I've been working on, and I have run into a problem that has me totally stumped. Essentially, the problem is that at a certain point in a ...
5
votes
1answer
132 views

Tikz Procedure/Function like abstraction? [closed]

I am pretty new to tikz but, so I do understand the basics, however, I am truly confused on what's the best way to create a procedure like constructs: there seems to be so many mechanism, and I cannot ...
4
votes
1answer
94 views

Why does \includegraphics[\varone]{\vartwo} not compile?

I want to convert each EPS image imported from within the input file to a PDF version and save it with its original name separately. The code below simulates the real condition in which we don't want ...
7
votes
1answer
143 views

Macros with binary trees as arguments

I would like to have some macros which have binary trees as arguments. For the purpose of these macros, a binary tree is either root or it is {branch1}{branch2} for two binary trees branch1 and ...
2
votes
1answer
196 views

Hooking in before \documentclass

In the consequence of a previously asked question (Is it possible to hook in after options have been processed in a certain package or class?) I had the idea of a hook that adds code even before ...
3
votes
1answer
59 views

Is it possible to hook in after options have been processed in a certain package or class?

In other words: Is it possible to scan the input stream of a .sty or .cls file (without using Perl) for \ProcessOptions\relax and nest some given code afterwords? (The filehook or etoolbox package ...
26
votes
2answers
754 views

Create a “List of Effective Pages”

I am considering learning Latex in order to more easily maintain a bunch of manuals for my company. One of the requirements is to have a "List of Effective Pages" towards the beginning of the ...
13
votes
1answer
196 views

What practices are there regarding the use or avoidance of “internal” TeX or LaTeX commands?

What practices are there regarding the use or avoidance of "internal" TeX or LaTeX commands? (About "command" vs "macro", there is some discussion in this TeX.SX answer, though I don't know whether ...
6
votes
2answers
419 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
1
vote
2answers
185 views

How to apply a macro to each row of a table

This is similar to the question about cells, but with whole rows, and hopefully will help me to implement an answer to this question. Given a macro \RowMacro, how can I define the mytable environment ...
19
votes
2answers
325 views

Difficulty with macro expansion

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} ...
13
votes
3answers
279 views

Gobbling an argument if it starts with #

My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic. ...
4
votes
2answers
262 views

Toggle visibility of solutions in LaTeX output for exams

So I have my own layout for my exams based on scrartcl and to prevent anomalies during some changes I want to have only one file per exam which holds both questions/excercises and solutions. Yet I ...
2
votes
0answers
35 views

Redefining macro with arguments in a macro with arguments [duplicate]

Possible Duplicate: What is the meaning of double pound symbol (##1) in an argument? In the following code, I would like to build one macro \caseWord with two arguments corresponding to ...
6
votes
2answers
339 views

How to make global a color list definition with \@namedef done inside a foreach loop

Motivation As stated in the title, I'm trying to define a command able, from a list of colors as input, to create a list in which colors are numbered. This, manually, has been done in Arrows ...
10
votes
0answers
151 views

Good beginner's guide to LaTeX programming [duplicate]

Possible Duplicate: Where do I start LaTeX programming? After a year of using LaTeX I've become fairly comfortable with troubleshooting common errors. As my confidence with LaTeX increases, ...
7
votes
1answer
117 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: ...
6
votes
1answer
310 views

How to define macros in a foreach loop with effects between iterations and after the loop without using global?

Without using \global, the following code: \documentclass{minimal} \usepackage[T1]{fontenc} \usepackage{tikz} \usepackage{etextools} \newcommand\appendbyforeach[2]{% ...
24
votes
3answers
1k 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 ...
3
votes
1answer
147 views

Is it at all possible to design a macro that expands to a length? [duplicate]

Possible Duplicate: Get width of a given text as length In an attempt to Compute the x distance between two nodes, the question arose whether it is at all possible to devise A macro that ...
21
votes
2answers
2k views

Can I access system/environment variables from LaTeX? For instance, $HOME

For instance, I want to include a figure: ~/figures/figure.pdf. On my Linux box, this is /home/me/figures/figure.pdf, but on OS X it is /Users/me/figures/figure.pdf. I'd like it if there is an ...
4
votes
1answer
113 views

Safeguard an environment against tabular mode

The semantics of a given environment require that it is typeset inside a minipage if it is used inside a tabular. If I add the minipage declaration for a positive check for "internal" mode in the ...
20
votes
1answer
200 views

Which of these two equivalent macro definitions should be preferred?

Consider the following two macro definitions: \def\setmacro#1{\def\macro{#1}} \def\setmacro{\def\macro} Although the two variants of \setmacro have a different \meaning they are equivalent in what ...
17
votes
3answers
720 views

What does \\* do?

I have some code, and when I use \\*, it causes some things to become unaligned, but when I use \\, the alignment is correct. What's the difference?
0
votes
2answers
229 views

TeX Programming questions (and stuff about parcolumns)

I'm trying to modify the inner workings of parcolumns. I'm starting to understand the TeX macro "programming" language a bit but I have some issues. In paracolumns there are three issues I want to ...
8
votes
2answers
268 views

Why are some macros undefined inside an if case?

I'm trying to check if a string is only of one char, and I ran into this problem: LaTeX complains that \StrLeft in the comparison takes and additional argument: ! Argument of \@secondoftwo has an ...
4
votes
4answers
450 views

Writing a multiple option command for a package

I am a newbie at LaTeX programming, so please be patient. :-) I am writing a .sty file which I want to include a command \dan which is overloaded with three separate versions depending on whether ...
7
votes
1answer
230 views

Why do some arguments in a macro need to be preceded by \noexpand?

I keep on studying the use of nested tikzpicture environments (sorry) and I discover the next problem. I'm not sure but it sounds like a problem with "fragile" commands. Perhaps, the problem is the ...
14
votes
3answers
773 views

Use \bgroup and \egroup to set some pre and post code to a macro

Why isn’t it possible to use \bgroup and \egroup in this way? \documentclass{article} \def\precode{\fbox\bgroup} \def\postcode{\egroup} \newcommand{\mymacro}[1]{\precode#1\postcode} ...
11
votes
2answers
4k views

Remove space after command

To simplify some text I created some commands. One command has no arguments. It uses math mode but is used inside normal text. I would like to remove any trailing space between the command and ...
7
votes
2answers
1k views

Passing arguments to \def inside \newcommand (TikZ/PGF)

I'm having trouble passing an argument to \pgfmathparse inside a macro I defined. Here is the code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \newcommand{\drawmestg}[2]{ ...
2
votes
1answer
238 views

Call macro whose name depends on macro

Sorry about the title, I really couldn't find a better one. I'm facing the following dilemma: I'm using the smartref package, in particular I'm using its \sgetXval macros. The thing is that I'm using ...
26
votes
3answers
7k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
21
votes
2answers
649 views

Which is better: a dimension or a macro?

When messing around with TikZ/PGF then I frequently find myself wanting to store a length for later use. By "length" here, I mean the word in its non-TeX meaning. As I'm doing stuff in TikZ/PGF then ...
2
votes
1answer
1k views

How to pass a \def parameter to an inner command (StrSubstitute)?

I'm attempting to create 2 macros to simulate an array list as in Java for example. I'm using xstring StrSubstitute for this purpose, but I'm having a problem. Below is the code, it's a bit long as it ...
8
votes
1answer
202 views

Compressing a list

I have an application, where I am using lists to store reference numbers of forms as shown below: \alist(1,2,3,4,4a,8,9,10,23,23b,28) As these lists get rather long, I would like to compress them ...
4
votes
3answers
759 views

How to use \def or similar command to store an arbitrary number of variables for later processing?

I'm trying to create a package for drawing simple sequence diagrams using PGF/TikZ. Here is the basic idea I'm stuck at (not the whole idea to make it short): Let's say we have 1 environment (say ...
3
votes
1answer
352 views

tkz-euclide, define points outside of tikzpicture

Is it possible to define points in tkz-euclide outside of the tikzpicture environment? For example I would like to have something like this exercise in elementary geometry: Exercise: Consider the ...
22
votes
4answers
4k views

Repeat command n times?

Is it possible to define a command, which repeats the following command n-times? Call it for example \Repeat, then \Repeat[4] \command{...} should be equivalent to \command{...} \command{...} ...
7
votes
1answer
177 views

How to cache the results of a macro

TeX's ability as a programming language can be leveraged to produce documents that include fairly sophisticated calculations. Although not everybody's cup of tea, such documents are akin to literate ...
22
votes
2answers
383 views

Delimiting a macro argument with the macro itself

Any command sequence can be used to delimit a macro parameter. Even one that has not been defined. For example: \def\YY#1,#2\@@{#1,#2} \YY123,2345\@@ will happily work, even if the macro \@@ has ...
9
votes
3answers
2k views

Defining a macro in LaTeX with an optional parameter in round brackets

Is it possible to build a macro with an optional parameter enclosed in round brackets () rather than square brackets, where one can say for example: \mymacro(){}{} or \mymacro{}{}
15
votes
2answers
1k views

How to add a hook to a macro

LaTeX uses hooks extensively, one method employed is the command g@addto@macro. It is defined in source2e as: \long\def\g@addto@macro#1#2{% \begingroup \toks@\expandafter{#1#2}% ...
21
votes
2answers
699 views

Stripping the pt from a dimension

LaTeX defines in ltfssbas.dtx a macro called \strip@pt (at line [246]) which strips the pt part from a dimension returned by \the\dimension. The definition is shown as a minimal working example below: ...