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

learn more… | top users | synonyms

15
votes
2answers
231 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
394 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
244 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
191 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
461 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
42 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 ...
7
votes
1answer
501 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
187 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
227 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
37 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
124 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
282 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
404 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 ...
11
votes
2answers
517 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
232 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
636 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
332 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
227 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
157 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
177 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
87 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
148 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
128 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
391 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]{% ...
27
votes
5answers
923 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
184 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
690 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 ...
30
votes
3answers
2k 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
162 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 ...
12
votes
3answers
311 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
135 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 ...
24
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 ...
16
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?
1
vote
1answer
350 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
146 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: ...
8
votes
1answer
221 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 ...
5
votes
1answer
119 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
202 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
193 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 ...
13
votes
1answer
342 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
452 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
567 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 ...
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 ...
17
votes
3answers
792 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?
0
votes
2answers
242 views

TeX Programming questions (and stuff about parcolumns)

I'm trying to modify the inner workings of parcolumns. I'm starting to understand the TeX macro "programming" language a bit but I have some issues. In paracolumns there are three issues I want to ...
5
votes
2answers
773 views

How to check if a font exists in XeLaTeX

Is there a way to check if a font exists in XeLaTeX? I am aware of Check for missing fonts/characters in XeLaTeX?, but sadly the one answer only refers to the log. I am interested for a test via code. ...
18
votes
2answers
1k views

Programming simple functions using TikZ arithmetic?

How do you do program simple functions using the TikZ arithmetic engine? I love the idea of using TikZ in order to “program” my pictures, being able to write code once and reuse, get precise ...
8
votes
2answers
294 views

Why are some macros undefined inside an if case?

I'm trying to check if a string is only of one char, and I ran into this problem: LaTeX complains that \StrLeft in the comparison takes and additional argument: ! Argument of \@secondoftwo has an ...