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

learn more… | top users | synonyms

3
votes
2answers
42 views

Creating a separated table

I'd like to be able to setup a bunch of things to put in a table after gathering them up before hand. Something like the following where I keep a variable with the contents that will eventually be ...
0
votes
0answers
39 views

design of code (full expansion, items extraction, deleting macro)

I have some datas like "A/x/1/\sqrt{2}" representing points (name/firstcoordinate/secondcoordinate/morecoordinate/...) which will be argument of the macro '\setpoint' doing the job (extracting name, ...
4
votes
1answer
125 views

Good examples of \tl_case:Nn(TF) and \str_case:nn(TF)

While learning expl3, I'm having a hard time in using \str_case:nn(TF) and \tl_case:Nn(TF). I failed to find good examples online. (E.g., the ones in unravel are too complicated for me.) Could you ...
1
vote
0answers
49 views

How to only render the contents that are sandwiched in a special environment?

The objective is to ease me to read the PDF output that is relevant to the part I am developing. In other words, every time I compile, I just want to focus on the part I am developing, other parts ...
5
votes
2answers
59 views

Sharing code between two classes

I'm writing two simple custom classes, one based on article and another based on book. They share some common code, such as font, margins, numering. I'd like to reuse the lines of code that are ...
5
votes
1answer
69 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
132 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
57 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{% {\psset{...
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
155 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
106 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}% 1)\IsArgaCs{\a}...
0
votes
0answers
78 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
39 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
42 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
63 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
188 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. \sigblock{0}{2}{...
14
votes
2answers
387 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
47 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
427 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
215 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
51 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
122 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
90 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
114 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
81 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]{ \stepcounter{...
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
104 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 \end{...
2
votes
0answers
61 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
37 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: \newcommand{\...
2
votes
1answer
100 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
257 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
67 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
99 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
60 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
46 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]{% \expandafter\newrobustcmd\csname#...
0
votes
2answers
21 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 mymacro\...
1
vote
2answers
43 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
361 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
64 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
85 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
165 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
23 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 ...