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

learn more… | top users | synonyms

102
votes
3answers
13k 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 ...
37
votes
8answers
2k 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} ...
26
votes
5answers
821 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 ...
15
votes
5answers
4k 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
5k 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 ...
24
votes
5answers
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{...} ...
14
votes
1answer
569 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 ...
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
4k 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 ...
12
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 ...
16
votes
3answers
707 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
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 ...
48
votes
10answers
5k 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 - ...
22
votes
8answers
892 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 ...
6
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
494 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: ...
16
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 ...
107
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). ...
55
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
2k 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
3answers
555 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
539 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 ...
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}% ...
3
votes
1answer
86 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 ...
21
votes
2answers
753 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
839 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 ...
27
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 ...
16
votes
3answers
483 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: ...
22
votes
2answers
3k 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
635 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 ...
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 ...
6
votes
1answer
725 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 ...
12
votes
1answer
323 views

ConTeXt: How do you create your own commands?

There seems to be a Current and Standard way to define new (core) commands in ConTeXt. For example, an e-mail by Wolfgang states: Many of the \define... and \setup... commands are now auto ...
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
2answers
514 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 ...
24
votes
1answer
425 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 ...
24
votes
3answers
525 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: ...
23
votes
2answers
398 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 ...
6
votes
1answer
341 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
304 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 ...
5
votes
2answers
130 views

Boolean key value in xkeyval fails

It is possible to hand over a boolean key value stored in a macro to a command such as \edef\SomeKeyValue{true}% \DummyCommand[DummyBooleanKey=\SomeKeyValue]%%% where DummyBooleanKey is a boolean ...
4
votes
2answers
298 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 ...
15
votes
3answers
2k views

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?
10
votes
3answers
816 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 ...