{programming} is about how (La)TeX can be used as a programming language.

learn more… | top users | synonyms

94
votes
3answers
11k 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 ...
26
votes
5answers
752 views

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 ...
35
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} ...
15
votes
5answers
3k 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 ...
34
votes
2answers
1k 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 ...
12
votes
1answer
4k 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 ...
19
votes
2answers
3k 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, ...
19
votes
2answers
3k 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 ...
11
votes
1answer
2k 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 ...
19
votes
3answers
2k views

Delete an element from a comma delimited list

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 ...
15
votes
3answers
679 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 ...
13
votes
1answer
510 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 ...
13
votes
3answers
5k 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 ...
47
votes
10answers
4k 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 - ...
21
votes
8answers
854 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 ...
25
votes
3answers
2k 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 ...
4
votes
1answer
2k 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. ...
5
votes
1answer
473 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: ...
103
votes
5answers
9k 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). ...
54
votes
6answers
3k 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 ...
33
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 ...
30
votes
2answers
1k views

TeX assistance in writing hidden acrostics

Here's a fun challenge. Try to come up with (and code) techniques through which (La)TeX can help authors to incorporate acrostics in their writing. The definition from Wikipedia: An acrostic is a ...
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{...} ...
22
votes
3answers
517 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
505 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 ...
3
votes
1answer
78 views

Extracting commands from environment

In Automatic scaling of tikz images in floatrow I was asking how to scale several images in one row to the same height and to scale the resulting row to linewidth. I would like to automate the ...
15
votes
5answers
1k 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 ...
21
votes
2answers
688 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: ...
31
votes
5answers
2k 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 ...
26
votes
2answers
736 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 ...
15
votes
2answers
2k 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 ...
15
votes
3answers
444 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: ...
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 ...
14
votes
2answers
619 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 ...
6
votes
1answer
658 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 ...
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 ...
10
votes
2answers
1k 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 ...
7
votes
3answers
1k 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 ...
24
votes
1answer
417 views

Bad interaction between fontspec and some lua code that performs string-related search and replace operations

Update 2013/05/28: The selnolig package is now on the CTAN. Comments and critiques always welcome! If you wish to contact me about any aspects of the package, please use the email address that's given ...
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}% ...
6
votes
1answer
304 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]{% ...
6
votes
1answer
285 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 ...
4
votes
2answers
250 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 ...
10
votes
3answers
751 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 ...
9
votes
6answers
929 views

Parse simple arithmetics and return the result

I want a command \ca which takes a simple arithmetic calculation as an argument and returns the result with proper decimal places. Additionally I want an boolean argument which decides if only the ...
7
votes
2answers
227 views

How can I store variables in lists and make use of them?

This question is clearly related to How can I store variables and iterate over them?. I'm sorry to ask such a close one, but I really don't understand the answer in plain TeX by David Carlisle. ...
6
votes
2answers
70 views

Reading number from file into variable — How to put a number into my document that increments with every compilation?

I am not that much into TeX/LaTex programming ... but what I want to do is the following: How to put a number into my document that increments with every compilation My ideas so far are: use a ...
6
votes
1answer
325 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 ...
34
votes
4answers
637 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 ...
31
votes
5answers
822 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 ...