{programming} is about how (La)TeX can be used as a programming language.
45
votes
2answers
5k views
Where do I start LaTeX programming?
I'm interested in writing packages for TeX/LaTeX/XeLaTeX. I googled around, but all I found was guides or tutorials about how to prepare documents using LaTeX. I want to know how LaTeX works and how ...
29
votes
8answers
1k views
How can I specify a long list of math operators?
The preambles of my LaTeX documents often include many many lines of \DeclareMathOperator instructions, e.g.
\DeclareMathOperator{\Rep}{Rep}
\DeclareMathOperator{\Tet}{Tet}
...
12
votes
1answer
3k views
How do you say Happy New Year with LaTeX?
Title says it all. How do you wish "Happy New Year" to a TeXie? Compile the code below with pdfLaTeX, view it with "PDF Reader" or "Adobe Acrobat Pro" and press the "Happy New Year" button on the ...
13
votes
3answers
561 views
LaTeX equivalent of ConTeXt buffers
While creating a series of graphics (using TikZ) in ConTeXt, I frequently use ConTeXt's buffer to "copy-paste" code. Is there a LaTeX package that implements this feature?
Since most LaTeX users may ...
12
votes
4answers
2k views
How to sort an alphanumeric list
I have been trying to find a package or a method to sort lists of names in an easy manner in TeX/LaTeX. I have tried some of the routines in the xfor package, as well as looked at some of the new ...
16
votes
3answers
1k views
Comma delimited lists
LaTeX's low-level programming is poorly documented and the section on what is called control commands is even more so.
LaTeX provides the \@for macro. This works by repeatedly assigning list items ...
8
votes
3answers
2k views
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 ...
39
votes
10answers
3k views
What is the best way to learn TeX?
As opposed to LaTeX, which is addressed in another question.
Most of the references I've seen get too complex too quickly. I'm looking for something that gives me a top-down view of the language - ...
19
votes
3answers
736 views
Convert any number to corresponding word
This is a wild one: can anyone write a code that converts a number into the corresponding word? e.g.:
4 -> 'four'
31 -> 'thirty-one'
and so on. Obviously, it is not enough to build an array ...
11
votes
1answer
862 views
Note page showing the next frame
I would like to customise the note pages in Beamer to show:
the current frame that they refer to with its number,
the next frame of the presentation with its number,
the section and subsection,
the ...
5
votes
1answer
288 views
Use a loop to generate a list for another (foreach) loop
Is it possible to use a loop to generate a list for a foreach loop? More specifically I want the following:
Consider the following answer to a question I asked some time ago: ...
4
votes
1answer
1k views
Hello World in pdfLaTeX
After many years being silent, TeX can now talk! Almost minimal code below! It should be of particular interest to Physicists and Cosmologists. Need to have Adobe Reader installed.
...
12
votes
1answer
302 views
Why is \input not expandable?
In latex.ltx I found \def\input{\@ifnextchar\bgroup\@iinput\@@input} where \@@inputis expandable. I would like to know if there is an expandable version of \input.
The problem comes from an example ...
86
votes
5answers
8k views
LaTeX3 versus pure Lua
Reading this site for the last nearly two years I've learned a lot about LaTeX3 (which I had previously understood to be a defunct pipe dream) and LuaTeX (of which I was previously totally unaware). ...
45
votes
6answers
2k views
Does TeX/LaTeX give a headstart with other programming languages?
I've seen many programmers here at tex.se, and I'd like to know how they view TeX/LaTeX as a programming language in relation to other languages, and whether it would boost my progress as a beginner ...
28
votes
2answers
776 views
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 ...
21
votes
8answers
727 views
What is the best way to scan over a list of somethings?
It seems that a common operation needed when defining new commands is to scan over a list of arguments (separated e.g. by a comma, but maybe by something else) and do something with each argument in ...
18
votes
2answers
321 views
How to compute the remaining space on the current page
Is there a way to compute the remaining space on the current page and issue an optional command?
18
votes
4answers
402 views
How do I get a value out of a group?
I've just recovered from my first real foray into LaTeX3 programming. It was ... an experience. Not a completely unpleasant one and once I'd gotten used to the syntax then I found it a lot easier ...
28
votes
4answers
1k views
A critique of TeX?
Is there any informative critique of TeX along one or all the lines below:
TeX, the typesetting engine (including its algorithms)
TeX, the typesetting language
TeX, the programming language
TeX, the ...
29
votes
5answers
1k views
Data structures for TeX
I often find myself wanting to use standard data structures in TeX. For example, lists or maps. Each time this need comes up, I reinvent the wheel. For some reason, I find myself using stacks fairly ...
20
votes
4answers
2k 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{...} ...
15
votes
2answers
1k views
Draw a prism in TikZ or PSTricks
Is there a way to define an polygon in plane and output an (orthogonal) prism with that polygon as its base? The prism should be drawn in 3D in parallel oblique perspective with controllable height h, ...
10
votes
2answers
1k views
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 ...
21
votes
2answers
798 views
What does \z@ do?
in parcolumns it has \z@ all over the space. I don't see it define it anywhere so I assume it is some internal command or something? I can't really make heads or tails of it though and I can't really ...
6
votes
1answer
409 views
Generating a worksheet
My objective is to be able to generate worksheets in categories like:
Laws of Indices
Simultaneous Linear equations and
Quadratic equations
When I say generate is to generate for example 20 ...
13
votes
5answers
722 views
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 ...
7
votes
3answers
553 views
[minimal] option for CV
I've been thinking of implementing an option for my CV where it extracts a set of predefined sections (in a minimal form) and typesets that instead of the entire list of everything I've done in my ...
6
votes
1answer
229 views
How can one undefine an already processed class option?
I'm using a class classX that accepts class option optionX. Thus, I can write:
\documentclass[optionX]{classX} ...
Now, as I understand it, being a class option, after classX processes this ...
9
votes
3answers
423 views
How to implement a command that checks for loaded packages?
I use the following code to check if a package is loaded:
\RequirePackage{ltxcmds}
\newcommand{\IfPackageLoaded}[2]{\ltx@ifpackageloaded{#1}{#2}{}}
However, sometimes I want to check if more than ...
8
votes
2answers
956 views
How to break out of a loop
I have been trying to automate the production of stepped tables that contain conversion factors of all sorts. (See Protrusion of fractions in tabulars).
As part of this I have a rather convoluted ...
6
votes
1answer
239 views
Problem with keys to emulate \rput with TikZ
This is a beta version of \rput with TikZ. I don't know if the psticks version accepts polar coordinates but I added this option. My problem is to add the options ref = B, Bl , Br, t, tl , tr, b, bl ...
30
votes
4answers
545 views
What's the folk-lore on automatic testing of TeX programming?
Say you write a macro or a package, which goes through the usual course of software life-cycle. How would you define a set of tests, and have this set run automatically to make sure that changes to ...
17
votes
2answers
276 views
How to generate a table of trigonometric functions that can be broken across pages?
Consider the following screenshot.
The features I want to have are:
I can shrink the page size and the table is allowed to break across pages.
The background of odd rows must be different from ...
29
votes
5answers
718 views
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 ...
15
votes
3answers
303 views
How to trim .tex for each filename read from an external file?
I have an external text file that contains a list of names of TeX input files. The names have trailing extensions .tex.
For example, the external text file named data.txt contains the following list:
...
12
votes
2answers
504 views
Improving TikZ user interface
I am looking to improve both on the concept as well as the user interface for code used to produce visual progress charts. The figure represents activities and progress
for the construction of ...
11
votes
3answers
685 views
whitespace/brace/indentation conventions for LaTeX programming
This question is not about formatting the text/markup of a document. I'm really focused on the programming aspect of LaTeX. I'm working on a fairly large set of document classes and packages, and ...
10
votes
4answers
456 views
How can I progressively scale letters?
How can I reproduce the figure below?
The figure is from an old Knuth paper, which you can get at http://www.math.lsa.umich.edu/~millerpd/docs/501_Winter08/Knuth79.pdf (page 364)
20
votes
2answers
522 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 ...
17
votes
3answers
510 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?
10
votes
1answer
211 views
ConTeXt (core) command definitions: what do \installcorenamespace, \?? and \installcommandhandler, do?
I have the very strong impression that there is a Current and Standard way to define new (core) commands in ConTeXt; see, for example, this quote from an e-mail by Wolfgang.
Many of the \define... ...
10
votes
1answer
443 views
What is the right way to set a dimension parameter?
In the TeXbook Knuth set parameters for dimensions mostly as follows:
\parskip=3pt
Other package authors define such parameters without using the equal sign
\parskip30pt
Many later authors use ...
9
votes
3answers
1k 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{}{}
4
votes
1answer
98 views
Summary based on environments/custom commands
Suppose I am taking notes in class and label certain things with my own environment like:
\begin{Theorem} Important Theorem Here. \end{Theorem}
or smaller key ideas labeled with my own command ...
23
votes
3answers
486 views
Saving a 100 tokens worth, is it worth it?
The LaTeX kernel defines a number of tokens that are used throughout the LaTeX source and the standard LaTeX classes. For example:
\def\hb@xt@{\hbox to}
This particular one is commented as:
...
22
votes
3answers
519 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 ...
20
votes
1answer
248 views
Bad interaction between fontspec and some lua code that performs string-related search and replace operations
I'm in the process of readying a LuaLaTeX package for "official" release to the CTAN, but I need to squash a few remaining bugs first. The bug described in this question concerns incorrect behavior of ...
14
votes
2answers
760 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}%
...
12
votes
2answers
311 views
How to emulate some options of \node from TikZ
Code
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \a in {0,45,...,315}%
{\node[line width = 0pt,
rotate = \a,
anchor = ...
