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

learn more… | top users | synonyms

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 ...
2
votes
1answer
191 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
380 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
202 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
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 ...
11
votes
1answer
564 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: ...
44
votes
0answers
863 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
194 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
143 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
265 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
55 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
343 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 ...
13
votes
3answers
299 views

Gobbling an argument if it starts with #

My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic. ...
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 ...
31
votes
2answers
1k views

What language is TeX implemented in?

I read on Wikipedia that the first version of TeX was written in SAIL. However, does anyone know what language later versions (i.e the current one) are implemented in?
7
votes
3answers
221 views

When to use or avoid grouping?

For writing my own TeX code, grouping (\begingroup, \endgroup) helps on automatically saving and restoring TeX "variables". (La)TeX "variables" are either macros or registers. The registers can ...
15
votes
2answers
223 views

Macro Improvements

I am looking to simplify and improve on the code below: \documentclass{article} \usepackage{filecontents} \begin{filecontents}{test.txt} a an and the this by on of \end{filecontents} ...
17
votes
2answers
358 views

Defining a dimension with or without @

If I am writing a TeX package (as one can find such on CTAN), there are following approaches to define a new dimension length that should be changeable by a user of that package. Approach A: Define ...
10
votes
2answers
218 views

How to make the last word in a sequence the first?

I am looking for a macro that would take a string (better to say -- a sequence of words) and output the last word at the fist place before remaning part of the sequence. I want to put this macro into ...
1
vote
0answers
162 views

Writing simple LaTeX workspace [closed]

I have this project in which I need to write something like a workspace for LaTeX. Basically I need to make split window. In one you would write the TeX code and in the other you would see the live ...
2
votes
0answers
62 views

How do I get my comma back (C++ lstlisting section) [duplicate]

Possible Duplicate: Comma inside \texttt{} does’nt show up I've been writing code in my book and just noticed that the comma has gone. I've been moving between machines so I don't know if ...
14
votes
2answers
366 views

Get number of elements in enumerate

Suppose, I have the following code: \documentclass{article} \begin{document} We have totally 7 columns, describing the user: \begin{enumerate} \item ID --- users.name \item Forename --- ...
1
vote
1answer
40 views

modifying PrintDescribeMacro of doc.sty

I would like to redefine the command PrintDescribeMacroof doc.sty in order to create a label that I can link to using hyperref. However whenever I add a label to the command I get an error ...
6
votes
1answer
396 views

Programming with pgf arrays : how to create an array?

I am trying to do some automatic drawing in tikz. The point is I want to be able to provide the minimal quantity of information to my macro, and still have it work. More precisely (but without ...
5
votes
2answers
157 views

How to write an environment wrapping document environment

I'm working on wrapping up some patterns used in my research group for creating posters. Since we're using beamer and beamerposter to make these, all documents go essentially like this: ...
10
votes
1answer
220 views

querying whether a font feature has been activated via a fontspec command

A LaTeX package I'm currently writing makes use of -- and definitely requires -- some of the power of LuaLaTeX. I would like to make my package's user interface -- in particular, the options that need ...
2
votes
0answers
35 views

Redefining macro with arguments in a macro with arguments [duplicate]

Possible Duplicate: What is the meaning of double pound symbol (##1) in an argument? In the following code, I would like to build one macro \caseWord with two arguments corresponding to ...
5
votes
1answer
120 views

Automatic results table for a problem set

I have problem sets with multiple problems where each problem gives a different number of points. Some are bonus points, some are regular points. I'd like to show a table with each problem and the ...
3
votes
0answers
266 views

What makes TeX so easy to write? [closed]

I have tried various different markup/markdown languages and have found myself coming back to TeX for the ease of typing. I have always wondered what are the features which make TeX such an ...
6
votes
2answers
367 views

How to make global a color list definition with \@namedef done inside a foreach loop

Motivation As stated in the title, I'm trying to define a command able, from a list of colors as input, to create a list in which colors are numbered. This, manually, has been done in Arrows ...
9
votes
2answers
415 views

\rand inside \forloop creates identical values

I try to create a table with random entries... By browsing the random tag, I found some help on random number generators and I tried using lcg. Surprisingly I seem to create the same random number ...
2
votes
1answer
215 views

Code for reading Metafont definitions

I need some C code to generate Bezier curves from Metafont source code. Ideally, I'd like to have a C/C++ function with the following specifications: Input: an array of text strings (the lines in the ...
16
votes
3answers
604 views

Can I use an easy programming language with XeTeX?

TeX is frustrating me. It has only the basics - and even then, I have to search how to divide two numbers. The question is this: can I write my macros in more convenient language like Ruby or Lisp? ...
3
votes
2answers
279 views

make command undefined [duplicate]

Possible Duplicate: How to undo a \def (i.e., Need a \undef capability) In my template I test for chapter defined to prevent that code section only valid for a chapter class are executed. ...
7
votes
1answer
220 views

Choice keys and exception handling

Recently, I switched a self-written "bundle package" from using xkeyval to keyreader. One reason for this, beside the backward compatibility, was that the definition of keys is more convenient in ...
10
votes
0answers
153 views

Good beginner's guide to LaTeX programming [duplicate]

Possible Duplicate: Where do I start LaTeX programming? After a year of using LaTeX I've become fairly comfortable with troubleshooting common errors. As my confidence with LaTeX increases, ...
3
votes
1answer
161 views

datatool repeat row

I intend to create a document where parts of the text are read from the entries of a .csv file using the package datatool (version 2012/09/25 v2.11., updated manually under debian). Everything works ...
6
votes
1answer
86 views

Dual form in bibtex style file

I'm writing a thesis in my language that, apart from singular and plural forms, has the dual form. I'm using bibtex and I'm having problems with translating the .bst style properly to support the dual ...
11
votes
1answer
145 views

How many different concepts of “token equivalence” are there in TeX?

I was living in the delusion that the "token equality" tested by \ifx was the only thing you need to remember about this subject, but this week I learned otherwise (thanks to David Carlisle). Now ...
8
votes
1answer
122 views

Package providing fully expandable conditionals

Is there a package providing a collection of fully expandable conditionals like this one: \newcommand\myif@num[1] {\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} Background: ...
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]{% ...
26
votes
5answers
820 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 ...
3
votes
2answers
177 views

replace folder separation char for index

In index the ! char is used for item separation. I have index strings which contain folders and files. These index entrys should look like \index{files!fonts/!fonts.tex} However I pass these to ...
7
votes
1answer
640 views

Programatically style words/sentences/paragraphs based on arbitrary metrics?

It'd be nice to be able to style words or sentences or subsections based on arbitrary metrics. For example, it might be useful to highlight words based on their length - bolder highlighting for longer ...
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 ...
3
votes
1answer
150 views

Is it at all possible to design a macro that expands to a length? [duplicate]

Possible Duplicate: Get width of a given text as length In an attempt to Compute the x distance between two nodes, the question arose whether it is at all possible to devise A macro that ...
11
votes
3answers
290 views

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 ...
2
votes
1answer
125 views

Equation numbers in loop

I am using the loop command to make an exam file with unique numbers, i.e., the whole exam text is repated and only the first page of the exam looks different. I am using equation numbers in the text ...
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 ...
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?