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

learn more… | top users | synonyms

3
votes
1answer
20 views

How to write text above and below \iff so that it works with breqn?

breqn makes the following code not work in one of my latex files, and I am not sure how to code it differently so that it works with breqn loaded as I need this package for other things. Here is the ...
4
votes
1answer
27 views

Append slopes of linear regressions to a pgfplotstable column

Suppose I have one pgfplots-axis with multiple data series. Now I loop over this and calculate a linear regression of each series. How can I store the slopes of the regression lines to a pgfplots ...
7
votes
4answers
413 views

How to write a command to format different letters?

I hope I can have a command MyFormatter, which can make letters p and k bold and make letters m and t italic. For example: \MyFormatter{Supermarket} will output as follows: Supermarket How ...
3
votes
2answers
43 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
41 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
131 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 ...
5
votes
2answers
61 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
73 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
140 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
62 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
159 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 ...
6
votes
6answers
190 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}{...
4
votes
3answers
108 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}...
9
votes
2answers
175 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 ...
0
votes
0answers
81 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
182 views

How to remove LaTeX control sequences from a .tex document using plasTeX?

I need to get just the text and math expressions (ignoring tables, pictures and styling) from a set of LaTeX documents and represent them in html. Looks like plasTeX and MathJaX are enough for this ...
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
44 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
64 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} \...
14
votes
2answers
412 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
49 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
432 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 ...
7
votes
2answers
133 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 ...
12
votes
3answers
220 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 ...
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 ...
2
votes
0answers
102 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{...
30
votes
8answers
7k views

Repeat command n times?

Is it possible to define a command, which repeats the following command n-times? Call it for example \Repeat, then \Repeat[4] \command{...} should be equivalent to \command{...} \command{...} \...
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 |...
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 ...
10
votes
1answer
298 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 ...
5
votes
2answers
94 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
117 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
66 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 ...
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
106 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{...
22
votes
3answers
411 views

Embed TeX as a typesetting system for an eBook reading application

Are there any projects or information on how to use TeX to typeset texts for screen reading? That is, I want to get the beautiful output of TeX to render in a browser-like desktop application. I want ...
11
votes
3answers
768 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
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 ...
4
votes
1answer
126 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 \...
17
votes
1answer
7k views

How do you say Happy New Year with LaTeX?

Title says it all. How do you wish "Happy New Year" to a TeXie? Compile the code below with pdfLaTeX, view it with "PDF Reader" or "Adobe Acrobat Pro" and press the "Happy New Year" button on the ...
5
votes
2answers
2k views

How can one get a list of the available functions in Lua(La)TeX

Is there a list or method to determine a list of the lua functions available/installed? Sofar I could only find the lua source files. Maybe I should write something that search through all the ...
11
votes
2answers
264 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} ...
6
votes
2answers
102 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 ...
4
votes
1answer
68 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 ...
2
votes
1answer
89 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 ...
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
47 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#...