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

learn more… | top users | synonyms

31
votes
3answers
1k views

Programming Conway's Game of Life in LaTeX

My aim is to program Conway's Game of Life in LaTeX, and make the output into an animated PDF. I intend to use PGF/TikZ for this, especially pgfmath, but I'm stuck at the moment because I need to ...
6
votes
2answers
75 views

Prime as an argument of command

Suppose we are in math-mode and I want to use command \E with the following behaviour. If one or two primes follow the command, i.e. \E' or \E'', then I want to have in these cases certain ...
7
votes
3answers
100 views

How to iterate through all user-defined control-words?

\documentclass[preview,border=12pt,varwidth]{standalone} \usepackage{pgffor} \def\Person#1{% \ifcsname#1\endcsname \else \expandafter\def\csname #1\endcsname{#1}% \fi ...
2
votes
1answer
92 views

Conditional assignment in a loop

Objective: I want to compile the temporary.tex file containing PSTricks code twice. One with -jobname=Rotated and the other one with -jobname=Unrotated. The resulting Rotated.ps will be passed to ...
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 ...
5
votes
2answers
89 views

How to redeclare $$ or the \[, \] pair

There might be probably many reasons not to do it, but what would be the proper way to redeclare the $$ sequence or the \[,\] pair to open by default some special display math environment, such as ...
5
votes
1answer
81 views

Making uses of cleveref packages standalone

I have used cleveref package for referring to equations, figures, etc in an article. However, I wish to compile my tex file on another system which only has a basic version of tex. I wish to make my ...
1
vote
0answers
60 views

Programing in Latex, if and? [duplicate]

I know about \ifthenelse. Is it possible to programming in LaTeX like in C, with loops and arrays?
3
votes
0answers
2k views

Programmatically generating LaTeX with Python [closed]

I'm fairly new to LaTeX and I want to generate some reports using Python. Here is some code that creates a simple table. After coding this up I began to wonder if there isn't a better way to do ...
8
votes
3answers
184 views

Simple Key Events table

Consider the simple time-line table shown in the image below (extracted from a book). and the MWE below defining it as an environment, \documentclass[twocolumn,10pt]{article} ...
6
votes
2answers
325 views

How to code an auto-increment counter in LaTeX

When typesetting letters is common practice to have a reference such as: XXX-yl-0001 Where the last number is incremented for each successive letter. Normally, I hand-code the number. When ...
3
votes
1answer
80 views

How to begin a package (newbie style)

I am kinda new in LaTeX, but I'm trying to make a "package" to display abstract structs algorithms in beamer. Ex: \binarytree[]{a->b.c, c->e.f} and my plan is to make this visual algorithm to ...
2
votes
1answer
194 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
57 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 ...
5
votes
1answer
172 views

Special daily calendar for whole year needed

I need to print out a special daily calendar sheet for every day of 2014. The solution here: Page a day calendar problems no longer is available, the link to mattjy.me is dead. The whole daily sheet I ...
26
votes
2answers
731 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 ...
2
votes
1answer
368 views

How to render LaTeX in programs?

Recently I'm writing a calc program, on android. As a frequent LaTeX user, it comes to be compelling to use LaTeX rendering in displaying the inputs and outputs. Is there any possibilities to use a ...
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 ...
1
vote
0answers
34 views

Is there a way to use a previous TikZ picture? [duplicate]

Let's say I spend some time drawing this picture: And after a few paragraphs I want to draw the same picture plus some "spices". Of course I could just copy-and-paste the code, then edit the few ...
13
votes
1answer
191 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 ...
2
votes
1answer
60 views

Conditional compilation failed

I think you can understand the scenario of the following code only by reading it. % compile with pdflatex -shell-escape \documentclass{article} \usepackage{filecontents} ...
21
votes
3answers
545 views

Best way to illustrate Keplers 2nd law with tikz

I am trying to visualize Keplers second law of planetary motion with tikz. I managed to do the following: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} ...
29
votes
1answer
1k views

How to generate “You can't use \unskip in vertical mode”?

We all know (or believe so) that \unskip is not possible in main vertical mode and this statement can be found in various answers on the site. And yes LaTeX does a lot of gymnastics in \addvspace or ...
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 ...
8
votes
1answer
95 views

How do the \xx_case: functions work?

In the process of answering expl3 switch for booleans: Is there a \bool_case:Nnn?, I tried to make sense of the various \xx_case: functions Expl3 provides. Here, for example, is \tl_case:Npn: ...
2
votes
1answer
134 views

Shuffle numbers in a loop

I want to have a document, where the exact same page will be printed for a certain number of pages and on every page there should be a unique number. I know how to do so with a loop, but I don't ...
6
votes
2answers
397 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 ...
8
votes
2answers
153 views

Can I store sequences in sequences with expl3

The documentation for l3seq states LaTeX3 implements a “sequence” data type, which contain an ordered list of entries which may contain any balanced text . but for many programming tasks it ...
1
vote
2answers
174 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
324 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} ...
40
votes
5answers
2k views

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. ...
2
votes
0answers
46 views

How to throw an error and abort the compilation for the following scenario? [duplicate]

Objectives: I want to throw exceptions (or error messages) when the following illegal code is invoked. \const[c,any]{temp}{\f[\i]} \const[others]{temp}{\f[\i]} Minimal Working Example: I cannot ...
7
votes
2answers
179 views

How to parse optional arguments without keyval?

The current implementation only supports rounding with the specified digits in the optional arguments. \documentclass{beamer} \usepackage{multido} \usepackage{pstricks} \usepackage[nomessages]{fp} % ...
1
vote
1answer
128 views

What causes this error? [closed]

After seeing Herbert's answer, apparently this problem should not occur if I realized the first row of the following code should be \documentclass{beamer}. Problems often come from not knowing what I ...
4
votes
1answer
102 views

How to implement a constant declarating macro to behave differently in preamble and pspicture?

The example below is extremely trivial just to illustrate the problem in the simplest way. \documentclass{beamer} \usepackage[nomessages]{fp} % constants declarator \def\LoadConstants{}% to load ...
6
votes
2answers
243 views

How to make the following recursive macro work?

For positive values less than 3 the following MWE works. \documentclass[pstricks,border=12pt]{standalone} \SpecialCoor \psset{showpoints=true} \def\Triangle#1{% \ifnum#1=1\relax ...
4
votes
2answers
127 views

Can't generate a tikz matrix, using expl3

Suppose, I want to generate a matrix of nodes: \documentclass{article} \usepackage{expl3} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture} \matrix [ row ...
3
votes
1answer
98 views

How to use a macro inside \tl_set:Nx

This code works: \documentclass{article} \usepackage{expl3} \usepackage{color} \setlength\parindent{0pt} \begin{document} \ExplSyntaxOn \tl_new:N \_text \tl_set:Nn \text {1} \tl_set:Nx \text ...
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 ...
2
votes
1answer
180 views

Compare two comma separated lists

Hi I would like to compare two comma separated lists. \documentclass[a4paper]{article} \usepackage{comment} \usepackage{ifthen} \usepackage{xargs} \usepackage{xkeyval} \usepackage{xfor} ...
6
votes
3answers
357 views

How to use data structures in TikZ?

I created a foreach statement, using expl3 and TikZ/pgf: \documentclass{article} \usepackage{tikz} \setlength{\parindent}{0cm} \usepackage{expl3} \ExplSyntaxOn \cs_new:Npn \Counter #1 \Stopper { ...
9
votes
3answers
187 views

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)} ...
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 ...
11
votes
1answer
456 views

Using \toks registers

I was reading this tutorial for TeX programming: http://pgfplots.sourceforge.net/TeX-programming-notes.pdf recommended in the 2-nd answer here: Where do I start LaTeX programming? It says: ...
36
votes
0answers
615 views

Can TeX generate “heap dumps” to analyze+optimize out-of-memory situations?

As package author of the memory-extensive package pgfplots, I have been asked to analyze some out-of-memory situation. I could identify the "culprit"; it was some call to \pdfmdfivesum in which it ...
11
votes
1answer
185 views

Loading latex from tex

I decided venture into the very basics of the world of TeX and LaTeX. I have been playing around with tex, pdftex and latex and after paying close attention to the binaries and not being able to ...
3
votes
0answers
138 views

Optimizing tikz code for less redundancies [closed]

I don't use tikz very often. When I do, I'm usually pretty happy with the result (and with how useful that manual is). But I always think the code I produced to get there could be optimized, as in the ...
4
votes
1answer
257 views

Is it possible to make LaTeX read the sectioning in reverse direction?

I want to make a note (for internal use only) while I am reading a book. For the sake of convenience, I want to put a note about the current topic I am reading on the first page of the PDF output to ...
3
votes
1answer
51 views

How to select all occurrences of a specified word in a string and append another word to each of them?

When using infix-RPN package, we can use \infixtoRPN to convert infix expression to RPN expression. The output of the conversion can be retrieved by invoking \RPN. \infixtoRPN{cos(x)+sin(x)}, for ...
14
votes
2answers
334 views

LaTeX3: How to get reliable control over the level of expansion?

Say you want to write LaTeX3 code that manages user data. Sometimes you want to process that data, but other times you just want to store it, move it around and return it unchanged (when developing a ...