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

learn more… | top users | synonyms

0
votes
0answers
51 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
76 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
38 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
34 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
95 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
38 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
228 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
117 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
63 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
79 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
57 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
37 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
18 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
35 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
112 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
60 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
71 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
66 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
43 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
96 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
20 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
136 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
38 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
165 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
57 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
93 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
460 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 ...
0
votes
0answers
44 views

Programming in Latex: Conditionals [duplicate]

I'm trying to learn how to programming in Latex. I want to make an if-else-statement. What I will do is something like this: \def\x{2} { \if x =2 Yes \else no \fi } But it doesn't work exactly how ...
6
votes
4answers
216 views

Automatically removing, after compilation, parts of text enclosed in certain strings

Is it possible to create a macro, such that everything that is between the string composed of the characters "whitespace", "{", "L" and the string composed of "L", "}", "whitespace" is not displayed, ...
6
votes
5answers
508 views

How can I draw several polygons on the same base line using TikZ?

I want to construct a figure that will be symmetrical polygons on the same base. So, there is an equilateral triangle, a square, a pentagon, a hexagon, etc. one side of all these is the same ...
3
votes
0answers
29 views

Can I force a pre-process action on all commands or environments without having to redefine them all manually?

I am trying to preserve a history of the latex commands and environment initializations I use in a typeset html or pdf file. Is there a way where I can force a pre-process action on all commands ...
3
votes
1answer
58 views

How to randomize comma separated rows to create word arrangement puzzles?

I have an external file named input.txt consisting of comma separated rows as follows. NOTE: The rows may contain Japanese characters as well. i, love, LaTeX, very, much i, am, a, student I want to ...
1
vote
1answer
83 views

Would it be possible to embed the lambda calculus in TeX?

I understand that TeX is Turing-complete. I'm just curious: would it be possible to embed the lambda calculus in TeX using TeX macros to fulfill beta-reduction?
1
vote
0answers
97 views

Is there any programming language similar to TeX? [closed]

I know nothing about programming, so TeXMaker's pseudo-WYSIWYG reminded me of a stereotypical programmer.
1
vote
1answer
98 views

Error when compiling using tikzmath

I am trying to learn how to use Tikz and its library Tikzmath to make graphics. I am trying to practice by drawing a series of circles along a line. My code is as follows: ...
4
votes
3answers
74 views

\forlistloop of etoolbox reference requested

I am having a problem of using the command of \forlistloop of etoolbox unlike the way of typical C program where int a[5] for ( i = 0; i <5; i++) { a[i] } one could access i I am not sure ...
15
votes
6answers
956 views

Loop within another loop in LaTeX

I am trying to create a loop within another loop using some of the constructs in etoolbox but I am not sure how to create that. I want to get the output like in C. pseudo code for (i in the list) { ...
2
votes
2answers
73 views

list environment where some items don't start new paragraph

I want to use a list-like environment, but I need to put some short items on the same line. The user interface will be something like: \begin{enumerate} \item First very long element \item* shrot ...
1
vote
1answer
52 views

Generating array with arrayjob and store values for further analysis

In a two-dimensional array I want to store some calculated values. However, for example for a 2 on 2 matrix I get identical values for [1,2] and [2,1]. What am I am doing wrong? ...
4
votes
3answers
211 views

Sorting according to absolute page height from pdf extensions

I'm unsure how to present the question, so I'll just go with something and edit if it is deemed necessary. The PDF extensions currently extend the basic TeX macros with at least the following three ...
4
votes
1answer
269 views

Calculate the hash (MD5 or otherwise) of a string

I'm trying to cache the results of a macro, similar to that question, but the argument of the macro can contain arbitrary characters and it's not suitable to be inside \csname ... \endcsname. So, I'm ...
2
votes
1answer
28 views

How can I include external macros for every line of the source code?

An answer to my last question gave a solution for hooking a small command onto line breaks in the TeX source. \documentclass{memoir} \usepackage[spacing, tracking]{microtype} \usepackage{libertine} ...
3
votes
1answer
118 views

Is there a formal grammar for *Equations* in TeX/LaTeX?

I've looked at this and this and understand there is no grammar of TeX as a whole. I am wondering if there is a grammar just for equations. They are relatively easy to identify in an amsmath file ...
13
votes
3answers
1k views

Hooking every line of the source code

I've been considering a more radical solution to the problem k.t.hagen posed a while back. Would it be possible (perhaps by catcode hijacking) to put hooks on individual lines of the source code? ...
3
votes
3answers
516 views

How to divide two values in LaTex [duplicate]

I need to divide two values in LaTex, \newcommand{\x}{30} \newcommand{\y}{10} Is there a simple way to do this? i.e x / y = 3 Preferably not using external packages, or a long winded ...
2
votes
3answers
183 views

How to inject a color into boxed objects?

Consider the following MWE. I want to give a color (red) to the boxed object (Hello). Unfortunately, it does not work as expected as if the boxed objects are shielded. How to remove such a shield? ...
2
votes
1answer
149 views

Perl, Python, Lua or just Latex/Xetex [closed]

Recently I finished my thesis in LyX and this was my first steps into latex (even indirect steps). Even though LyX does a lot of thing automatically, when you want to do something yourself, then ...
3
votes
1answer
74 views

Is there any method available to automatically show the ruby when writing sentences with Japanese Kanji?

I want to write a note for my study on Japanese Language with LaTeX. So far I have to write the ruby (furigana) for each Kanji manually such as \ruby{天}{てん}. It seems to be tedious and makes my input ...
4
votes
2answers
173 views

Count number of elements in a list

This question is somewhat similar to Count the number of elements of each size in a list. It should actually be simpler but I nevertheless can't figure out how to do it without using the same code as ...
8
votes
0answers
88 views

Table of contents with xtemplate (expl3)

Every time I typeset some book or articles, I start to renew sectioning commands (\part, \section, some \@-commands and so on), \maketitle, \tableofcontents commands by copy-pasting it to my class and ...