{programming} is about how (La)TeX can be used as a programming language.
Questions tagged [programming]
644 questions
43
votes
5 answers
How to print the permutation of {s,u,v,a,t} with LaTeX?
I want to use LaTeX to print the permutation of a set {s,u,v,a,t}. The output looks like the following.
suvat
suvta
suavt
suatv
...
There are 120 rows in total that must be generated on the fly.
How to do this with…
kiss my armpit
- 36,086
42
votes
5 answers
Is there a script that reads a TeX file and replaces every instance of a \newcommand?
I'd like to know if there's a script that reads a .tex file and replace every instance of a non-standard TeX command with whatever it is replacing. I am not sure if what I want is clear but let me give an example:
Suppose the input is:…
kan
- 4,545
42
votes
2 answers
Implementing a pullquotes algorithm in LaTeX
In pullquotes, I provided a manual technique for typesetting pullquotes in LaTeX. The technique was to typeset the material in two long narrow columns and then position them so as to join them together. A typical left column would look like the…
yannisl
- 117,160
32
votes
5 answers
Stack datastructure using LaTeX
A very common programming data structure is a stack. A stack is simply a one dimensional array. Stack elements are pushed in or popped out of the stack one at a time as LIFO (Last In First Out).
I am trying to build a general routine to represent…
yannisl
- 117,160
22
votes
2 answers
Accessing environment variables within a document
Is there a way to access environment variables from within a LaTeX document?
Suppose I define a variable in a batch file:
set MY_VAR=HelloWorld
How can I programmatically print the string "HelloWorld" inside my LaTeX document, without resorting to…
Marcus Fry
- 885
21
votes
3 answers
Explanations about \begingroup\edef\x{\endgroup
I see the code
\begingroup\edef\x{\endgroup
in the answer to this question.
I want to understand the purpose of this method. In which cases should it be used?
Alain Matthes
- 95,075
17
votes
5 answers
How can I store variables and iterate over them?
I want to know how I can store variables so I can iterate over them.
Say we have this input in the document:
\inputcommandname{first input}
\inputcommandname{second input}
\inputcommandname{third input}
Later in the document we write something like…
Håkon Malmedal
- 3,712
17
votes
3 answers
how to create switch structure comparing strings in latex
I want to process options that get passed to a package with kvoptions.
The string is then saved in \bugs@errorlevel.
I want to test if it contains one of [info, warning, error] and
set a command accordingly.
I could think of setting a bool variable…
Matthias Pospiech
- 11,681
16
votes
4 answers
Getting the last token of a macro argument
It is easy to get the first token of a macro argument. Ignoring some irrelevant complications, you do something like this:
\def\firsttokof#1{\first(#1)}
\def\first(#1#2){#1}
It's equally easy to get all the remaining tokens after the first…
Leah Velleman
- 662
16
votes
1 answer
pdflatex.exe on both dualcore-cores?
Is it possible to load pdflatex on both dualcore-cores of my Intel Core2Duo-Processor? At the moment, pdflatex just uses one core while the second core stays idle.
I got a pretty big document of 200 pages with many non-eps-pictures…
Thomas
11
votes
2 answers
Where is the argument?
I have this code on my hard disk and now I would like to understand it. Firstly I would like to know if this code is correct and logic or if there is another way to do the same thing.…
Alain Matthes
- 95,075
11
votes
1 answer
Three dots instead of \ldots
When writing the TeX-codes we often use the 6-symbols \ldots command. It should be more comfortable to type merely three dots ... instead. Just the same as for TeX-parsing the minus symbols - or -- or ---. So I wonder, is it possible reprogram…
user40791
11
votes
3 answers
Refactoring TeX/LaTeX code
Below is some shortened version of some code I wrote that can automatically format a number from decimal to scientific notation. I have been using it for some time now and have a few ideas how to combine it with some other work I have done into a…
yannisl
- 117,160
10
votes
2 answers
\CatchFileDef vs ( \input or \@@input )
I discovered catchfile here and now I would like to understand how works this package.
Below some tests with \foreach or \@for
\documentclass{article}
\usepackage{filecontents,catchfile,pgffor}
\begin{document}
\def\mylist{1,2,3,4}
Test…
Alain Matthes
- 95,075
10
votes
3 answers
How to use \toks with \foreach
I would like to use \foreach to replace the next code :
\def\x{0}
\edef\y{\x}
\xdef\z{(b\y)}
\def\x{1}
\edef\y{\x}
\xdef\w{\z(b\y)}
\def\x{2}
\edef\y{\x}
\xdef\z{\w(b\y)}
\def\x{3}
\edef\y{\x}
\xdef\w{\z(b\y)}
\w
The aim…
Alain Matthes
- 95,075