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

learn more… | top users | synonyms

4
votes
2answers
241 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 ...
7
votes
2answers
221 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. ...
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
210 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
213 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
322 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
198 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
151 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
296 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
314 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
145 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
217 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
116 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
254 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
322 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
328 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
198 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
564 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
234 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
204 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
150 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
149 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
84 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
139 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 ...
7
votes
1answer
114 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
294 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
744 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
166 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
565 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 ...
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 ...
3
votes
1answer
144 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
263 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
114 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 ...
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
3answers
1k 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?
1
vote
1answer
268 views

Looking for HAML and CoffeeScript support

I need support for HAML and CoffeeScript like other languages already got with the listings package. Do you know any solutions?
5
votes
2answers
138 views

\let versus conditionals for customizing macro behavior

I have a large collection of macros that do different things but all eventually use the same macro internally (call this macro \tasks). Sort of like this, but with better macro names: ...
7
votes
1answer
208 views

TeX equivalent to #line

In C there is #line which allows stating the origin of a particular line of code. This is useful for autogenerated C source files: The (unreadable) code in the generated file is mapped back to the ...
4
votes
1answer
111 views

Safeguard an environment against tabular mode

The semantics of a given environment require that it is typeset inside a minipage if it is used inside a tabular. If I add the minipage declaration for a positive check for "internal" mode in the ...
20
votes
1answer
199 views

Which of these two equivalent macro definitions should be preferred?

Consider the following two macro definitions: \def\setmacro#1{\def\macro{#1}} \def\setmacro{\def\macro} Although the two variants of \setmacro have a different \meaning they are equivalent in what ...
10
votes
3answers
178 views

What is the advantage of using \@testopt?

I discovered recently \@testopt in this question. I tried to understand the goal with the use of this macro, but in my research I discovered other macros like \@protected@testopt and even new packages ...
11
votes
1answer
295 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 ...
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 ...
3
votes
2answers
311 views

Number of \ (backslash) characters in a string

I'm trying to built a code that counts the number of \ in a string. My code can work with any other symbols (for example, if I need to count the number of 'a's, that works). I already tried to modify ...
18
votes
4answers
499 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
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 ...
17
votes
3answers
696 views

What does \\* do?

I have some code, and when I use \\*, it causes some things to become unaligned, but when I use \\, the alignment is correct. What's the difference?