Questions tagged [programming]

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

Filter by
Sorted by
Tagged with
13 votes
2 answers
662 views

Fun titles by splitting in letters (or words)

I want to display titles using a spelling routine I have found in this interesting discussion. The idea is that different simple effects can be easily selected. Unfortunately the code below has some ...
e_moro's user avatar
  • 888
13 votes
3 answers
1k views

Gobbling an argument if it starts with #

My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic. ...
JLDiaz's user avatar
  • 55.7k
13 votes
2 answers
5k views

Note page showing the next frame

I would like to customise the note pages in Beamer to show: the current frame that they refer to with its number, the next frame of the presentation with its number, the section and subsection, the ...
Harold Cavendish's user avatar
13 votes
2 answers
3k 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. ...
yannisl's user avatar
  • 117k
12 votes
6 answers
3k views

Parse simple arithmetics and return the result

I want a command \ca which takes a simple arithmetic calculation as an argument and returns the result with proper decimal places. Additionally I want an boolean argument which decides if only the ...
student's user avatar
  • 29k
12 votes
4 answers
635 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 ...
galex-713's user avatar
  • 431
12 votes
2 answers
974 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 ...
Matthias Pospiech's user avatar
12 votes
2 answers
2k views

Include ALL pdf graphics in document

I have several plots saved as .pdf in a folder and I would like to know if there is a way of adding all of them in a document at once, without typing the path to each file.
Eduardo's user avatar
  • 277
12 votes
1 answer
1k views

What is the right way to set a dimension parameter?

In the TeXbook Knuth set parameters for dimensions mostly as follows: \parskip=3pt Other package authors define such parameters without using the equal sign \parskip30pt Many later authors use ...
yannisl's user avatar
  • 117k
12 votes
3 answers
634 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 ...
Alain Matthes's user avatar
12 votes
1 answer
435 views

Loading latex from tex

I decided venture into the very basics of the world of TeX and LaTeX. I have been playing around with tex, pdftex and latex and after paying close attention to the binaries and not being able to ...
jmlopez's user avatar
  • 223
12 votes
1 answer
624 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 \...
Marco's user avatar
  • 26.1k
12 votes
0 answers
11k views

Programmatically generating LaTeX with Python [closed]

I'm fairly new to LaTeX and I want to generate some reports using Python. Here is some code that creates a simple table. After coding this up I began to wonder if there isn't a better way to do this....
stuckintheshuck's user avatar
11 votes
4 answers
1k views

Position of largest element in a list

Consider the following: \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_eq:NN \calc \fp_eval:n \ExplSyntaxOff \def\valueA{7} \def\valueB{19} \def\valueC{41} \def\valueD{31} \def\...
Svend Tveskæg's user avatar
11 votes
3 answers
508 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 ...
Alain Matthes's user avatar
11 votes
4 answers
558 views

Condition within condition

Consider the following logical satatements: If \conditionA != 100 and \conditionB != 100 do ``Something~A'' If \conditionA != 100 and \conditionB = 100 do ``Something~B'' If \conditionA = 100 and \...
Svend Tveskæg's user avatar
11 votes
3 answers
987 views

Smart-expansion of a range to a list of numbers

I am wondering if there is a simple way to expand some input text such as "3-7" as "3,4,5,6,7"? For context, I am using \foreach and want to be able to write \foreach \x in {3-7, 9, 14, 52} and ...
ryanj1823's user avatar
  • 301
11 votes
1 answer
2k views

How to write a real "Hello World" program

One of the easiest tasks in almost all programming languages is to write a program that writes "Hello World" into the terminal. Something similar in TeX is: tex '\empty Hello world! \bye' ...
M0M0's user avatar
  • 423
11 votes
1 answer
84k views

Three dots instead of \ldots

When writing the TeX-codes we often use the 6-symbols \ldots command. It should be more comfortable to type merely three dots ... instead. Just the same as for TeX-parsing the minus symbols - or -- or ...
user avatar
11 votes
2 answers
374 views

Where is the argument?

I have this code on my hard disk and now I would like to understand it. Firstly I would like to know if this code is correct and logic or if there is another way to do the same thing. \documentclass{...
Alain Matthes's user avatar
11 votes
3 answers
2k views

Refactoring TeX/LaTeX code

Below is some shortened version of some code I wrote that can automatically format a number from decimal to scientific notation. I have been using it for some time now and have a few ideas how to ...
yannisl's user avatar
  • 117k
11 votes
3 answers
2k views

whitespace/brace/indentation conventions for LaTeX programming

This question is not about formatting the text/markup of a document. I'm really focused on the programming aspect of LaTeX. I'm working on a fairly large set of document classes and packages, and I'...
11 votes
2 answers
412 views

How to emulate some options of \node from TikZ

Code \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \a in {0,45,...,315}% {\node[line width = 0pt, rotate = \a, anchor = ...
Alain Matthes's user avatar
10 votes
4 answers
807 views

How can I progressively scale letters?

How can I reproduce the figure below? The figure is from an old Knuth paper, which you can get at http://www.math.lsa.umich.edu/~millerpd/docs/501_Winter08/Knuth79.pdf (page 364)
yannisl's user avatar
  • 117k
10 votes
2 answers
14k views

How to typeset VBA code in LaTeX?

I have a lot of VBA (Visual Basic for Applications, the programming language in Microsoft Office) code which I have to add to my thesis in the appendix. I wonder how I can most comfortably list those ...
MostlyHarmless's user avatar
10 votes
3 answers
454 views

How to use \toks with \foreach

I would like to use \foreach to replace the next code : \def\x{0} \edef\y{\x} \xdef\z{(b\y)} \def\x{1} \edef\y{\x} \xdef\w{\z(b\y)} \def\x{2} \edef\y{\x} \xdef\z{\w(b\y)} \def\x{...
Alain Matthes's user avatar
10 votes
2 answers
509 views

How to make the last word in a sequence the first?

I am looking for a macro that would take a string (better to say -- a sequence of words) and output the last word at the fist place before remaning part of the sequence. I want to put this macro into ...
Igor Kotelnikov's user avatar
10 votes
3 answers
1k 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 ...
long tom's user avatar
  • 1,079
10 votes
3 answers
1k views

programmatically drawing sinusoids with tikz

Here's eight full oscillations of a sine wave: Here's the code: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[gray!20] (0,-2) grid (32,2); %...
voices's user avatar
  • 2,039
10 votes
2 answers
237 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\\} \edef\mmm{\...
frogatto's user avatar
  • 255
10 votes
1 answer
7k views

Hello World in pdfLaTeX

After many years being silent, TeX can now talk! Almost minimal code below! It should be of particular interest to Physicists and Cosmologists. Need to have Adobe Reader installed. \documentclass{...
yannisl's user avatar
  • 117k
10 votes
2 answers
1k 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} \...
Alain Matthes's user avatar
10 votes
1 answer
364 views

Moving from pgfkeys to latex3 key-val system to handle package options

I have been advised in this question to move from pgfopts to latex3 to handle package options. I would like to do that but I must admit that I am a little lost. Examples with the patterns I'm using ...
Vincent's user avatar
  • 5,257
10 votes
1 answer
3k views

How can I define NaN in LaTeX3

LaTeX3 l3fp offers a way to check if a variable has a an infinite value. The following code defines a number and then sets its value to π/2. It then calculates tan(π/2) to get a large result. \...
yannisl's user avatar
  • 117k
10 votes
2 answers
797 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} ...
Ricardo Pérez's user avatar
10 votes
1 answer
409 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 ...
Mico's user avatar
  • 508k
10 votes
1 answer
201 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: Let'...
Stephan Lehmke's user avatar
10 votes
2 answers
290 views

expl3: lowercase a token list

I want to convert to lowercase a token list that is composed by letter, digits and the control sequence \\. I try to use \str_lowercase:n but the control sequence is not covered also to text. \...
TeXtnik's user avatar
  • 5,853
10 votes
1 answer
1k 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]{% \AfterGroup*{\noexpand\...
Paul Gaborit's user avatar
  • 70.9k
10 votes
0 answers
202 views

create list of thumbnails for each section [closed]

I want to create a cooking book. There I want to define for each receipe a thumbnail image. At the beginning of each chapter I want to show instead of a TOC a gallery of thumbnails of each subsection (...
Matthias Pospiech's user avatar
10 votes
0 answers
298 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, I now ...
Kpantzas's user avatar
  • 803
9 votes
3 answers
3k views

Defining a macro in LaTeX with an optional parameter in round brackets

Is it possible to build a macro with an optional parameter enclosed in round brackets () rather than square brackets, where one can say for example: \mymacro(){}{} or \mymacro{}{}
Chuang's user avatar
  • 579
9 votes
2 answers
3k views

Are there "methods/functions" in Latex?

In programming languages, you can define methods and functions which can get called from other methods or functions. This allows for modularity and readability in software. Is there an analogous ...
Phillip D.'s user avatar
9 votes
4 answers
1k views

Removing duplicates from a list

Is there a LaTeX kernel command to remove duplicates from a list? The list has the structure \def\alist{john,mary,george,australia,australia}
yannisl's user avatar
  • 117k
9 votes
2 answers
631 views

Mark command as obsolete

Is it possible to declare some command inside a package as obsolete? I work on a package and want to inform users that in the next version of the package this commands will be deleted. What kind of ...
Konstantin Morenko's user avatar
9 votes
2 answers
3k views

LaTeX programming comparison operators

The example for the forloop package is \newcounter{ct}\forloop{ct}{1}{\value{ct} < 5}{\arabic{ct}}. I need to compare two counters having the first run up to the second. <= doesnt work, neither ...
peter's user avatar
  • 2,905
9 votes
1 answer
2k 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 ...
F'x's user avatar
  • 3,011
9 votes
2 answers
312 views

Difference between the V function parameter specifier and the o specifier in LaTeX3 programming

In LaTeX3 programming, how does the V function parameter specifier differ from the o specifier? How is the o specifier meant to be used in contrast to the V specifier? A related question: V vs. x
Evan Aad's user avatar
  • 11.1k
9 votes
2 answers
1k views

Programmatically Illustrating Permutations

Here's an illustration of what's known as an expansion permutation (the top half). It just means that instead of going straight through (like the bottom half aka. the identity permutation), the signal ...
voices's user avatar
  • 2,039
9 votes
3 answers
3k views

Multiply fine tuning with a thinspace \,

What I want is a redefinition of command \, to the version \,[N] for given integer N \, % standard usage \,[2] % the same as \,\, \,[3] % the same as \,\,\, and so on The usage of \hspace instead ...
user avatar

1 2
3
4 5
13