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

learn more… | top users | synonyms

5
votes
1answer
53 views

Interactive console at terminal evaluating commands

As I'm using LaTeX (in my case xelatex), I often run into little gotchas. As a programmer from other more functional or procedural languages, it really grates me that I can't easily figure out what an ...
5
votes
3answers
122 views

How to assign arbitrary LaTeX text to a variable for use in different places in a document?

I have lots of LaTeX text duplication in my files, since the file has to compile with pdflatex and tex4ht and text4ht does not support all packages, So my files are littered with things like this all ...
4
votes
1answer
49 views

Improve PSTricks code

Consider the following very ugly PSTricks code: % latex file.tex % dvips file.dvi % ps2pdf file.ps \documentclass{article} \usepackage{pst-text,pst-slpe,pstricks-add} \newcommand*\kurve{% ...
1
vote
0answers
13 views

Text Column Overfill (Non-Tabular)

I am working on a 2 column article and am getting warnings that some of my sections are "Overfilled" in specific places. In the preview I see some words spill over into the margins. This spill-over is ...
4
votes
1answer
149 views

How do I get list of all predefined \if commands in LaTeX?

I was trying some programming in LaTeX and found that \ifx was predefined, since I get an error from this: \documentclass[10pt]{book}% \newif\ifx \xtrue \begin{document} \end{document} Then I found ...
9
votes
2answers
173 views

How to save and restore the nodes between tikzpictures?

My English is not good enough so I beg you to excuse me if the question is long The next code is not very interesting but it may illustrate correctly my problem. I have a lot of macros and I need ...
4
votes
3answers
105 views

What is the best way to check if an argument of a control sequence is a control sequence?

I try to find a way actually I get update : \documentclass{article} \def\IsArgaCs#1{% \ifcat\relax\noexpand#1true \else false \fi% }% \begin{document} \def\a{a}% \let\b=~% \def\c{1}% ...
0
votes
0answers
76 views

Can you feel the ink on your paper?

While thinking on the question How to flip certain pixels of a QR code? I came up with ideas which would require to test the following: is_something_already_in_my_document_at_position(x,y) which ...
2
votes
1answer
35 views

Test if package with given options can be loaded

I need to introduce in my preamble a conditional structure to load a package if its complete version is installed, load its light version if it exists, or load some standard package otherwise. The ...
1
vote
1answer
41 views

Calculating descriptive statistics

I'm writing a paper that involves many values. In order to be consistent in all the papers, I'm using \def and xint to assign and calculate these values. However, in part of this paper I have to ...
7
votes
2answers
62 views

How to handle syntax errors in a macro?

I would to indicate in the log file that if I use () instead of {} in the line \macro[red,circle]{2/3/a,4/4/b,5/0/c}, an error occurs . What is the best way to do this ? \documentclass{article} ...
6
votes
6answers
183 views

How to write macro with variable amount of text variables

I am trying to make a signature block macro that accepts a variable number of text variables so that I can add or subtract the text without using empty fields "{}" as arguments. ...
14
votes
2answers
367 views

Is there any reason not to use \let to redefine a deprecated control sequence to the currently recommended one?

I understand that \bf and \it are both deprecated in the current version of LaTeX. To the best of my knowledge, the correct control sequences replacing them are \bfseries and \itshape. Is there any ...
3
votes
3answers
45 views

error when using \num command from siunitx package with an array from arrayjob package

I want to use the command \num from the siunitx package with some numerical data stored in an array data structure of the arrayjob package but I get an error message that I understand but I can't ...
12
votes
4answers
423 views

High-order recursive macro to define several similar macro at once does infinite loop

I’m a fan of factorization and hate code repetition. So I was trying to define a macro which defines for me all the common mathematical sets commands (\C, \N, etc.) and made a recursive function ...
1
vote
0answers
28 views

Embedding Cmx.io code in LaTex?

This may seem a bit silly, but here goes. There's a project called Cmx.io that allows you to create xkcd-style comics using an HTML markup. I wanted to include comics like these in a book I am ...
12
votes
3answers
212 views

Cyclic permutation of arguments / list of arguments

I work on a triangle ABC and I would like a macro to define IJK the centroid triangle ( I, J and K are the midpoints of the segments BC, AC and AB). The problem is not to get these points but "how" to ...
3
votes
1answer
50 views

How to use active characters to create hyperlinks with hyperref inside a PDF?

I want to create links inside a pdf and actually I use \hypertarget{label}{target caption} and \hyperlink{label}{link caption} with the package hyperref. Perhaps it's possible to use something like ...
7
votes
2answers
118 views

Problem between pgfkeys, tikz and personal macro

The following minimal working example shows the problem. The mainmacro is an example of what I need; here I want to use my keys and keys from tikz (like draw,color,shape). The result is fine only if I ...
2
votes
0answers
42 views

Figure/animation creation in LaTeX [closed]

What is one of the most complex/difficult figures that was created entirely in LaTeX? Is it possible to draw the globe figure that one can see here on TEX in the background just above the "Ask ...
5
votes
2answers
84 views

Using multline or equation based on a boolean flag

I am trying to define a new environment myeq which can either be an equation or a multline. My use case is that in the preamble, I will define myeq to be either replicate the functionaly of equation ...
10
votes
1answer
110 views

How to get around a problem with \usetikzlibrary{babel}?

I am currently working on an update of tkz-euclide and new documentation but I just met the following problem. If I compile this code with pdflatex or lualatex and pgf 2.1 (The library babel does not ...
2
votes
0answers
72 views

Using For loop in latex to input multiple files in different directories

\documentclass{minimal} \usepackage{chngcntr} \usepackage{pgffor} \newcounter{question} \newcounter{answer} \setcounter{question}{0} \setcounter{answer}{0} \newcommand\Que[1]{ ...
0
votes
0answers
55 views

What language is TeXLive written in? [duplicate]

I read that TeX was written in SAIL and re-writen in Pascal. Do we still use that version today? In my Linux distribution, I use TeX-Live. Does that also use the Pascal version? Wikipedia says the ...
2
votes
2answers
101 views

How to append data to a global string variable?

Here is a minimal non-working example: \documentclass{article} \begin{document} \let\@var\@empty \newcommand{\append}[1]{ \xdef\@var{\@var #1} } \append{1} \append{2} \append{3} \@var ...
2
votes
0answers
59 views

search for and highlight words/numbers in pdfpages while only printing highlighted pages

I have a project where it would be very helpful to be able to include pdf pages with certain text and or number highlighted, and in addition limit the pages output to those which have the highlighted ...
2
votes
1answer
35 views

Doing case analysis on an argument of a macro

Background: As has been discussed here, there appears to be no widely accepted typographical standard for logical quantifiers. To address this I defined in my paper the following macro: ...
2
votes
1answer
99 views

Need help with macro-driven tables and expantion

This is a project I have been working on for a while now and I am stuck on implementing this new function, cell coloring. My function works by taking in an unknown amount of data called 'weapons' and ...
3
votes
2answers
42 views

How to process only tokens containing a lower case letter?

The goal is to have a macro with single argument, that looks at all tokens in turn and if it sees a lower-case letter it is wrapped in \texttt{<token>}. All other tokens are passed through ...
11
votes
2answers
250 views

Extract source code on the fly to a file?

I'm trying to create a programming text to use for my students. My goal is to have an environment (say, "code", for instance), so, if I type the following in my .tex file: \begin{code}{Sample script} ...
4
votes
1answer
124 views

How to make a list of environments?

I know that LaTeX/TeX is a complete programming language, but I can not find any topic about making list or vectors, as it is in C# or C++. My goal is to make a list, where I store names of my ...
4
votes
1answer
66 views

How to prevent XeLaTeX from dynamically enlarging or shrinking space after comma?

See the following output. Question How to prevent XeLaTeX from dynamically enlarging or shrinking space after comma? force XeLaTeX to break long sentences automatically without having to ...
6
votes
2answers
98 views

How to perform lexicographic sort on list of coordinates in LaTeX?

I need to sort a list of TikZ coordinates, first by increasing X coordinate and then by increasing Y coordinate. At the moment I do this by invoking an external Python shell, but it would be nicer to ...
2
votes
1answer
59 views

My \Render that attempts to iterate a list and invoke macros dynamically produces errors

My \Render that attempts to iterate a list and invoke macros dynamically produces errors. The given MWE with detailed comments tells what my objective is. How to fix it? I have no more idea how to fix ...
1
vote
1answer
44 views

How to iterate a list and do something for each element? [duplicate]

For an illustration, see the following MWE. MWE \documentclass{article} \usepackage{etoolbox} \newcommand\Push[1]{\gappto\Array{#1}} \newcommand\NewItem[2]{% ...
0
votes
2answers
20 views

How to dynamically create, set, and use conditional?

It is better if I give an illustration as follows. A statically created and invoked macro \newcommand{\mymacro}{test} \mymacro A dynamically created and invoked macro \expandafter\csname ...
1
vote
2answers
40 views

How to create a dynamically created macro with optional argument?

The following MWE does not compile (unfortunately). The objective is to create a dynamically created macro, for example, \Newton with an optional argument. If \Newton is invoked, $F=ma$ will be ...
1
vote
0answers
309 views

LaTeX for automatic report generation

I accept that this question might be a bit outside the scope of this page, but please bear with me! At work I'm going to set up a framework for generating some pretty basic reports, which could be on ...
3
votes
1answer
61 views

What makes my array-like macro get contaminated

The following MWE is the simplified version of my project. \CreateMacro is used to create macros representing vocabularies. For example, \CreateMacro{Newton}{$F=ma$} creates \Newton with body $F=ma$. ...
1
vote
3answers
74 views

Insertion fails when invoked in \chapter

Here is the simplified version of my project. I have a macro named \CreateMacro which takes 2 inputs, i.e., the macro name to create and its body. For example, invoking \CreateMacro{Newton}{$F=ma$.} ...
2
votes
1answer
81 views

Is there a way to have xesearch search and replace a term and have the replacement compiled as LaTeX command?

I have used the package xesearch https://www.ctan.org/pkg/xesearch?lang=en xesearch in my header to automatically replace shorthand notations: \usepackage{xesearch} \SearchList{list1}{Very Long ...
0
votes
0answers
44 views

Why this fatal error occurs? (trying to align a text in tikzpicture) [duplicate]

I would like to print a code in my document in the format that is very common to see online in many websites like this: But when I try to compile, a fatal error occurs. The problem is in the ...
4
votes
1answer
154 views

is it possible to write a function ( programming language) with latex

I am writing out equations and a lot of my equations have parameters changed but the basic structure is repeated. I have reduced the problem to a hypothetical example as follows. if (condition ==2) ...
2
votes
1answer
21 views

How to define global macros on the fly across multiple enumerate environments?

I want to create macros defined right after \item of enumerate environment. Those macros must be global in such a way that redefining the same macros in another enumerate must produce error. I failed ...
10
votes
2answers
145 views

Ignore expansion in edef

I would like to populate a tabular environment programmatically using an edef. For simplicity, I brought a simple example: \let\\=\relax \let\hline=\relax \edef\mmm{\hline A & B\\} ...
1
vote
1answer
77 views

Read a text file by delimiter not by line break

I would like to populate a table, which I created in my LaTeX document, using iterating over cells of a text file. In order to read the text file I use this code. \newread\data \openin\data = data ...
5
votes
3answers
193 views

How to append at the end of each \item?

I have an input file with a lot of items enclosed in enumerate. For an unknown reason, I have to append something (by calling a macro) at the end of each item. I don't want to modify the existing ...
1
vote
1answer
68 views

Add text only if a variable has been defined

I am not sure this is possible nor how I can accomplish this and thus I can't include a MWE. I assume though that stuff like this is used to create LaTeX packages. The idea is to add a table row (or ...
5
votes
1answer
94 views

How to automatically invoke all defined macros?

First of all, make sure you have installed Kanji Stroke Order font before trying to compile the following MWE. The font can be downloaded here (click). I want to create a note about my study in ...
25
votes
4answers
484 views

Expandable (quick) sort array macro?

I'm trying to implement a (quick) sort algorithm. Here is what I can do : \documentclass[preview, border=7mm]{standalone} \usepackage{pgffor} % \push{xs}{\i} add \i in the array \xs ...