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

learn more… | top users | synonyms

10
votes
1answer
215 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
34 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
113 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
246 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
296 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
281 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
193 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
533 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
206 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
195 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 ...
9
votes
0answers
148 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
139 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
81 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
135 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 ...
6
votes
1answer
108 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
269 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
686 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
155 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
501 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
844 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
248 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
108 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 ...
20
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
241 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
136 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
196 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
109 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
194 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
172 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
284 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 ...
32
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
251 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
481 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
992 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
657 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?
28
votes
2answers
2k views

What does \z@ do?

in parcolumns it has \z@ all over the space. I don't see it define it anywhere so I assume it is some internal command or something? I can't really make heads or tails of it though and I can't really ...
0
votes
2answers
221 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 ...
4
votes
2answers
568 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
251 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 ...
3
votes
2answers
221 views

Taking user input during compile

Deeply inspired by Paulo Cereda's answer on the ways TeX can be used apart from document creation. If you haven't seen the program mentioned: it's a Reversi TeX game that during the compile asks the ...
10
votes
1answer
309 views

Storing and retrieving data in tuc file

I want to store some data in the .tuc file, which is being picked up in the next run. I suceeded in storing some values but I failed in retrieving them afterwards. Here is my attempt: \starttext ...
4
votes
1answer
113 views

Summary based on environments/custom commands

Suppose I am taking notes in class and label certain things with my own environment like: \begin{Theorem} Important Theorem Here. \end{Theorem} or smaller key ideas labeled with my own command ...
8
votes
2answers
187 views

\CatchFileDef vs ( \input or \@@input )

I discovered catchfile here and now I would like to understand how works this package. Below some tests with \foreach or \@for \documentclass{article} \usepackage{filecontents,catchfile,pgffor} ...
7
votes
2answers
256 views

how to test if tikz library is loaded

I want to write some demo code showing code with examples for tikz. However I want the resulting pdf to be automatically depended on the tikz libraries and therefore I must test which are loaded. Is ...
4
votes
4answers
365 views

Writing a multiple option command for a package

I am a newbie at LaTeX programming, so please be patient. :-) I am writing a .sty file which I want to include a command \dan which is overloaded with three separate versions depending on whether ...
7
votes
1answer
226 views

Why do some arguments in a macro need to be preceded by \noexpand?

I keep on studying the use of nested tikzpicture environments (sorry) and I discover the next problem. I'm not sure but it sounds like a problem with "fragile" commands. Perhaps, the problem is the ...
12
votes
3answers
669 views

Use \bgroup and \egroup to set some pre and post code to a macro

Why isn’t it possible to use \bgroup and \egroup in this way? \documentclass{article} \def\precode{\fbox\bgroup} \def\postcode{\egroup} \newcommand{\mymacro}[1]{\precode#1\postcode} ...