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

learn more… | top users | synonyms

13
votes
2answers
606 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 ...
5
votes
2answers
242 views

how to write content of a command into a file

This question is a possible solution to question Code fails with Emergency stop, when using \expandafter\csname and such in listings, though not really an answer. I have defined a command which may ...
0
votes
1answer
669 views

Code fails with Emergency stop, when using \expandafter\csname and such in listings

I am further working on my code for LaTeX Examples. I want to use the package showexpl for the simultaneus printing of code and results. Unfortunately I get an '! Emergency stop.' ...
4
votes
2answers
213 views

TeX evaluates 'document' code in preamble

I have the error ! LaTeX Error: Missing \begin{document}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.30 \AddDemo{text}{Sample Text} in ...
7
votes
2answers
341 views

how to compare two booleans?

I want to test if either inputenc or selinput are loaded. My problem now is to do complex boolean expressions and I have no clue how to do that with LaTeX. The basic code would be something like ...
13
votes
3answers
4k 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 ...
4
votes
1answer
170 views

forLoop does not accept negative step?

I try to use \forLoop for a countdown sequence: \documentclass{minimal} \usepackage{forloop} \usepackage{fmtcount} \begin{document} \newcounter{idx} \forLoop[-1]{10}{1}{idx}{\numberstring{idx}\\} ...
0
votes
2answers
304 views

Environment with customizable number of table columns

I want to make macros for drawing group of questions with same answers with customizable text, number of answers and design (column widths, alignment, etc.), like this: ...
24
votes
3answers
1k 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 ...
25
votes
3answers
7k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
4
votes
1answer
475 views

stack.sty and \end{environment}

I'm writing a multilevel itemize list environment to simplify the process of putting nested lists in Beamer slides, and I want it to support enumerate lists as well. The mitemize environment is ...
3
votes
4answers
692 views

Generating dummy text programatically using TeX/LaTeX

As part of an attempt to debug another problem, I have a need for a TeX/LaTeX command that generates some dummy text in place. I know of lipsum and blindtext, but they are not what they want. What I ...
5
votes
2answers
868 views

How can one get a list of the available functions in Lua(La)TeX

Is there a list or method to determine a list of the lua functions available/installed? Sofar I could only find the lua source files. Maybe I should write something that search through all the ...
0
votes
1answer
354 views

Problems with error message when using listings-package and inputenc.

I want to include the code of some script in my LaTeX document. In a "minimal" example, it works perfectly well - but only if I leave out the line \usepackage[latin1]{inputenc}: ...
7
votes
2answers
2k views

How to typeset VBA code in LaTeX?

I have a lot of VBA (Visual Basic for Applications, the programming language in Microsoft Office) code which I have to add to my thesis in the appendix. I wonder how I can most comfortably list those ...
2
votes
1answer
175 views

How can I display nested lists (the programming-datastructure) in LaTeX?

I would like to write something in LaTeX, where I need nested lists. It should be displayed like this: segment = [ [ [0,1,0],[1,1,1],[0,1,0] ] [ [1,1,1],[1,1,1],[1,1,1] ] ...
2
votes
1answer
2k views

How to generate LaTeX documents with Perl

I have to generate Software Requirement Specification documents in LaTeX. I have to use Perl to accomplish this. The documents consist of tables, lists, pictures, TOC, table of figures, headings and ...
3
votes
2answers
375 views

binary representation of an integer

Is there a way to get a binary string of an integer calculated by e.g., \pgfmathparse{pow(2,3)} \pgfmathresult such that later on I can use the string digits in a foreach loop like .. if it is '1' do ...
21
votes
2answers
641 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 ...
2
votes
1answer
1k views

How to pass a \def parameter to an inner command (StrSubstitute)?

I'm attempting to create 2 macros to simulate an array list as in Java for example. I'm using xstring StrSubstitute for this purpose, but I'm having a problem. Below is the code, it's a bit long as it ...
8
votes
1answer
200 views

Compressing a list

I have an application, where I am using lists to store reference numbers of forms as shown below: \alist(1,2,3,4,4a,8,9,10,23,23b,28) As these lists get rather long, I would like to compress them ...
9
votes
2answers
821 views

LaTeX programming comparison operators

The example for the forloop package is \newcounter{ct}\forloop{ct}{1}{\value{ct} < 5}{\arabic{ct}}. I need to compare two counters having the first run up to the second. <= doesnt work, neither ...
6
votes
2answers
268 views

Where can i find programming techniques material

i want to learn to do some basic style programming with latex, I'm searching a bit but i can't find a clear source of information. I'm searching things like Conditionals Loops Comparison ...
4
votes
3answers
739 views

How to use \def or similar command to store an arbitrary number of variables for later processing?

I'm trying to create a package for drawing simple sequence diagrams using PGF/TikZ. Here is the basic idea I'm stuck at (not the whole idea to make it short): Let's say we have 1 environment (say ...
7
votes
3answers
991 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
3answers
230 views

Removing duplicates from a list

Is there a LaTeX kernel command to remove duplicates from a list? The list has the structure \def\alist{john,mary,george,australia,australia}
10
votes
4answers
788 views

Implementation of a C compiler in TeX ?

Seeing the many things already done with TeX, I wonder if anyone has implemented a C (or C++) compiler in TeX. This does not seem too far fetched as an experiment. I do not expect great performance. ...
3
votes
1answer
346 views

tkz-euclide, define points outside of tikzpicture

Is it possible to define points in tkz-euclide outside of the tikzpicture environment? For example I would like to have something like this exercise in elementary geometry: Exercise: Consider the ...
4
votes
1answer
638 views

SQL Markup and CSV Formatting in LaTeX

I have had a quick look for similar questions but I couldn't find anything, so apologies if this is a duplicate. Firstly, I am looking for a way to grab information from external source files (i.e. ...
12
votes
2answers
353 views

How does one detect whether one is in the preamble or not?

In LaTeX, I'd like to know whether a documentclass has been loaded and whether code is inside a \begin{document}. In other words, is there a \ifpreamble similar to \ifvmode and friends? ...
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{...} ...
7
votes
1answer
175 views

How to cache the results of a macro

TeX's ability as a programming language can be leveraged to produce documents that include fairly sophisticated calculations. Although not everybody's cup of tea, such documents are akin to literate ...
22
votes
2answers
377 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 ...
3
votes
2answers
908 views

Figure environment not working with included file (extra } or forgotten endgroup)

I've spent hours on this issue. I hope someone can help me. I'm running into some kind of interference when I try to use the figure environment (Likewise for table, might be related to floats). I ...
9
votes
3answers
2k 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{}{}
6
votes
1answer
198 views

Asserting reference inequality

Is there a way for including assertions in a LaTeX document? I want to check that some condition is true, and only allow compilation of the document if it is (or at least complain otherwise). ...
86
votes
2answers
10k 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 ...
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 ...
9
votes
3answers
673 views

Refactoring TeX/LaTeX code

Below is some shortened version of some code I wrote that can automatically format a number from decimal to scientific notation. I have been using it for some time now and have a few ideas how to ...
34
votes
4answers
630 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 ...
5
votes
2answers
170 views

How do I capture the existing color of a group?

My question is a follow-up of my answer to this question Color underline a formula My answer would have been much better, if I could save the color of the text and then restore it. Is it possible ...
10
votes
4answers
535 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)
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
2answers
425 views

LaTeX sphack family of commands.

LaTeX offers a number of commands that can be used in macros that want to be invisible i.e., not leave any extra space when used in the middle of text. These macros include \@esphack, \@bsphack, ...
2
votes
2answers
1k views

How can I process an array using TikZ 2.00 syntax?

I use TikZ/PGF 2.00. In the CVS PGF manual pag. 563 we have \def\myarray{{1,"two",2+1,"IV","cinq","sechs",sin(\i*5)*14}} \foreach \i in {0,...,6}{\pgfmathparse{\myarray[\i]}\pgfmathresult, } My ...
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 ...
3
votes
3answers
317 views

How to capture a colon in a macro?

I am trying to capture punctuation marks and I have a number of macros, two of which are shown in the minimal below: \documentclass{article} \usepackage[english]{babel} \def\isColon#1{% \ifx:#1 ...
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 ...
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}% ...
10
votes
1answer
554 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 ...