Skip to main content

Questions tagged [programming]

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

Filter by
Sorted by
Tagged with
5 votes
1 answer
144 views

Mapping structure in LaTeX3

I'm developing a LaTeX class for typesetting theses at the University of Trento, aiming to streamline every aspect of the thesis formatting process. One feature I want to implement is allowing ...
Emanuele Nardi's user avatar
0 votes
1 answer
53 views

Unecessary checks before calling `\cs_if_exist_use:cTF`?

Consider this wrapper as an example: \prg_new_conditional:Nnn \check_engine:n{p,T,F,TF}{ \tl_trim_spaces_apply:nN{#1}\__check_engine:n } \cs_new:Npn \__check_engine:n #1{ \bool_lazy_any:nTF{ ...
Vincent's user avatar
  • 5,801
1 vote
0 answers
60 views

Problem with conditional: TF version working, but not the p version

I reused the code provided as an answer here (I tried to make it a new conditional) \prg_new_conditional:Npnn \if_font_exist:nnnn #1#2#3#4{p,T,F,TF}{ \group_begin: \tl_if_empty:nF{#1}{\...
Vincent's user avatar
  • 5,801
2 votes
1 answer
96 views

tl_trim_spaces and tl_if_blank?

Is there any input for which, once processed with tl_trim_spaces could lead to tl_if_blank being true AND tl_if_empty being false?
Vincent's user avatar
  • 5,801
1 vote
2 answers
146 views

LaTeX3 version of expandafter-ifx-csname?

I currently have this code from a previous question (link here) \NewDocumentCommand \IfFontTF {mmmmmm} {% \begingroup \fontencoding{#1}\fontfamily{#2}\fontseries{#3}\fontshape{#4}\try@load@...
Vincent's user avatar
  • 5,801
2 votes
2 answers
91 views

What does \token_if_expandable:N(TF) actually test?

In LaTeX3 am wondering what \token_if_expandable:N(TF) actually test? The documentation says: Tests if the ⟨token⟩ is expandable. This test returns ⟨false⟩ for an undefined token. but I am guessing ...
Vincent's user avatar
  • 5,801
0 votes
2 answers
68 views

Understanding expansion patterns related to \exp_args:Ne

I have read tens of pages on expansion, and for whatever reason, I am still missing a clear understanding. To help me understand, I would like to focus on a specific example. Consider the following ...
Vincent's user avatar
  • 5,801
5 votes
4 answers
334 views

How to check if a font exists with pdflatex?

When using XeTeX or LuaTex and fontspec, one can use \IfFontExistsTF{font name}{yes code}{no code}. What would be the best way to test if a font exists/can be loaded when fontspec is not available (...
Vincent's user avatar
  • 5,801
1 vote
1 answer
94 views

Check if an input is a dim or a skip/muskip in an expandable way?

I am wondering how to create efficient expandable functions in LaTeX3: \check_if_dim:n \check_if_skip:n \check_if_muskip:n that would check if an argument can be parsed as a dimension, a skip or a ...
Vincent's user avatar
  • 5,801
2 votes
1 answer
87 views

What is the role of \tl_to_str:n versus using directly the functions from the l3str module?

Let's say I am creating an expl3 macro: \cs_new:Nn \my_function:n{ % Something } I have hard time understanding the exact role of \tl_to_str when processing the argument compared to "just&...
Vincent's user avatar
  • 5,801
2 votes
1 answer
93 views

Efficiently checking if an input can be parsed as a floating-point number in an expandable way in LaTex3?

I am trying to implement a function in LaTeX3 \check_if_fp:n that checks if an input can be parsed as a floating-point number (in an expandable way, so not using regexes). After a lot of thinking I ...
Vincent's user avatar
  • 5,801
0 votes
1 answer
41 views

Macro to change babel's caption for pre-defined sections for any language

So I came up with this handy little macro that in principle can change any pre-defined babel spanish caption: \newcommand{\spacaptchange}[2]% { \addto\captionsspanish% { \renewcommand*{...
Juan Manuel's user avatar
2 votes
2 answers
328 views

Implementing MATLAB code in LuaLaTeX

First of all I am aware of the complexity involved in the following question, but I wonder if something similar has been already solved (maybe even partially) by someone, who was interested in this ...
Richard's user avatar
  • 228
3 votes
2 answers
86 views

Using plural for appendix if more than one

Consider the following code, which adds the plural word appendices rather than appendix, if there is more than one appendix. I have added Babel and German, just for testing and a google translation ...
yannisl's user avatar
  • 119k
4 votes
3 answers
207 views

Expansion in Latex3 when transforming an input and forwarding it to another function

There are still a lot of mystery around expansion in LaTeX for me, but even given that, there is something I don't understand in LaTeX3. Let's say (just for the example), that I want to test whether ...
Vincent's user avatar
  • 5,801
0 votes
4 answers
102 views

How to detect inner spaces at the document level forwarded to token lists in LaTeX3?

Unprotected spaces are not treated as items in token lists in LaTeX3. If I have some argument coming from the document/user level, and I would like to detect if this argument have an inner protected ...
Vincent's user avatar
  • 5,801
0 votes
2 answers
48 views

Check if a predicate is satisfied on all tokens in LateX3 using conditionals

I am trying to write an expandable conditional that test if a condition is satisfied and it does not seem to work as expected. Currently here is my approach (with \token_if_letter_p as an example of a ...
Vincent's user avatar
  • 5,801
6 votes
1 answer
163 views

Long and protected macros in LaTeX3

I have questions about the following functions in LaTeX3: \token_if_macro_p:N \token_if_long_macro_p:N \token_if_protected_macro_p:N \token_if_protected_long_macro_p:N How do they behave with the ...
Vincent's user avatar
  • 5,801
3 votes
3 answers
317 views

Testing if a string is a hexadecimal string in LaTeX3: code review, optimization, expandability, and protection

Consider the code in LaTeX3. It tests whether a string is a hexadecimal string (optionally also testing the length of that string) (a string where every character is either 0-9 or A-F). \documentclass[...
Vincent's user avatar
  • 5,801
0 votes
0 answers
65 views

Fast way to test if an argument is a HTML color-code in LaTeX3?

I recently asked how to test if an argument is an integer using LaTeX3 (here). I am wondering how to use the same approach to test if a string correspond to a HTML color-code. Currently, I use the ...
Vincent's user avatar
  • 5,801
3 votes
1 answer
106 views

Branching on whether a color is defined using xcolor or xcolor-material?

I am trying to branch on whether a color (defined in xcolor or xcolor-material or using the utilities provided by these packages) has a name that can be used in the \color command (from the xcolor ...
Vincent's user avatar
  • 5,801
0 votes
2 answers
71 views

Splitting and forwarding to bool_lazy_any in LaTeX3?

I currently have a function which does the following: \NewDocumentCommand{\myfunction}{m m m}{ \str_if_eq:eeTF{\c_sys_engine_str}{#1}{#2}{#3} } which allows me to do something as: \myfunction{...
Vincent's user avatar
  • 5,801
2 votes
2 answers
145 views

Build a new command "newsymbol" with NewDocumentCommand

I want to create a new command \newsymbol, which functions like \newcommand, but with the difference that math is ensured. I also have another reason, why I want to define this new command, namely so ...
Make42's user avatar
  • 1,832
4 votes
1 answer
132 views

Why \IfPackageAtLeastTF{⟨package⟩}{⟨date⟩}{\PassOptionsToPackage{⟨option⟩}{⟨package⟩}}{} doesn't pass ⟨option⟩ to ⟨package⟩?

My current version of parskip is 2021-03-14 so: \IfPackageAtLeastTF{parskip}{2018-08-24}{\PassOptionsToPackage{indent}{parskip}}{} \usepackage{parskip} should pass the indent option to parskip. But ...
Denis Bitouzé's user avatar
0 votes
0 answers
25 views

How can I adjust the spacing between the number and the title of each level in TOC to create automatically a nested list?

In this code, I have defined custom sectioning formats using the titlesec package. However, I'm having trouble adjusting the spacing between the section numbers and titles, especially when the section ...
Antonio Maria Di Mauro's user avatar
3 votes
2 answers
250 views

Best Practices for Integrating Computer Algebra Systems (CAS) into LaTeX Documents

I am currently working on enhancing my LaTeX documents to involve complex mathematical equations. Managing these equations manually often leads to errors, especially when changing dependent equations ...
Foad's user avatar
  • 1,215
2 votes
1 answer
59 views

How to trim spaces without expanding what is inside in expl3?

Consider the following pattern: \NewDocumentCommand{\mycommand}{m}{ \myinternalcommand:n{#1} } \cs_new:Nn \myinternalcommand:n{ \tl_if_single:nTF{#1}{TRUE}{FALSE} } and let's say that I want ...
Vincent's user avatar
  • 5,801
3 votes
1 answer
158 views

LaTeX3 regex not working

I have a very strange bug and I guess I am not using LaTeX3 regexes as they are supposed to be used. My current document looks like this: \documentclass{standalone} \ExplSyntaxOn \regex_new:N{\...
Vincent's user avatar
  • 5,801
1 vote
3 answers
69 views

In Latex3, how to test if all tokens in the input verify a test (for example \token_if_letter or \token_if_space)?

In Latex3, I would like to write a function that checks if every token of an input verify a predicate. Basically I would like the multitoken version of this command: \NewDocumentCommand{\mychecksingle}...
Vincent's user avatar
  • 5,801
6 votes
2 answers
372 views

if_exist macros in LaTeX 3: what are they doing if they do not check the type of things they are supposed to check?

In the documentation of interface3, for several macros with the pattern xxxx_if_exist for xxxx being bool, str, seq and many others the following appear: Tests whether the <boolean> is ...
Vincent's user avatar
  • 5,801
1 vote
1 answer
241 views

Is LaTeX a programming framework of TeX?

My take from What is the difference between TeX and LaTeX? is that TeX is the programming language that renders the document. LaTeX is a well-known macro package for TeX with the aim to make the ...
Ooker's user avatar
  • 1,550
3 votes
3 answers
668 views

Put many images into multiple pages programmatically

I have many images, for example image01.jpg image02.jpg ... image80.jpg I want to put those images into a document, 8 images per page, 4 rows and 2 columns (assume they will fit into one page that ...
Lu Xu's user avatar
  • 137
10 votes
1 answer
417 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,801
4 votes
2 answers
109 views

Difference betwen .is family and .cd in pgfkeys in the context of package writing?

I am using pgfopts to create my own packages and handle options. .family and .cd can be used to group the package options together, but I am not sure to understand the pros and cons of each approach, ...
Vincent's user avatar
  • 5,801
5 votes
3 answers
241 views

Counting the number of occurences of specific characters in a string in an expandable way

This question shows how to count the number of occurrences of a specific character in a string. I would like to do it in an expandable way, and for a list (not only one) of specific characters. \...
Vincent's user avatar
  • 5,801
0 votes
0 answers
105 views

Detect if something is a length?

Is there a way in LaTeX to detect if something is a length with a function of the form: \NewDocumentCommand\iflength{m m m}{%CODE HERE%} where: the first parameter is the thing to be tested the ...
Vincent's user avatar
  • 5,801
0 votes
2 answers
129 views

A macro to check command expandability

I would like to create a command that checks whether an expression is fully expandable, and crashes if not (ideally printing an error message). I would like to do that without a specific TeX engine in ...
Vincent's user avatar
  • 5,801
0 votes
1 answer
68 views

Branch to something when an expression cannot be evaluated by fpeval

I would like to design a \comparator expandable command that relies on fpeval that has 3 branches: true branch when the comparison is equal to 1 false branch when the comparison is equal to zero ...
Vincent's user avatar
  • 5,801
0 votes
1 answer
99 views

In expl3, how to test if something, once fully expanded, contains any character belonging to classes 11 or 12?

I am wondering in expl3 syntax (not using the most recent additions, let's say additions posteriors to 2018 [nothing special about 2018, it's just an arbitrary date to say not too recent]) how to test ...
Vincent's user avatar
  • 5,801
1 vote
0 answers
103 views

Design a generic numeric comparator function using expl3 working for strings, counters, numexpr, dimexpr

I would like to design a generic compare function between numbers, ideally expandable with the following signature: \NewExpandableDocumentCommand{\compare}{r[] m m m m m}{%CODE HERE%} that would be ...
Vincent's user avatar
  • 5,801
4 votes
3 answers
150 views

Problem with a command that prefixes words only if needed when the arguments are provided through macros

Consider the following code coming from this answer, where it adds a prefix to a word, only if the prefix is missing. \documentclass[border=6pt,varwidth]{standalone} \ExplSyntaxOn \...
Vincent's user avatar
  • 5,801
5 votes
4 answers
330 views

An expandable command that adds a string to an argument if the string is missing

I would like to write and expandable command which adds a string S1 at the beginning of another string S2 if S2 does not start with S1 in order to ensure that my string always start by S1. I currently ...
Vincent's user avatar
  • 5,801
1 vote
2 answers
80 views

Macros to change pgfkeys package options on the fly and define custom sets of options

Consider the following code for a package : % Preamble \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{mypackage}[2024/01/01 MyPackage] \makeatletter % Dependencies \RequirePackage{pgfopts} \...
Vincent's user avatar
  • 5,801
1 vote
1 answer
39 views

Command color not working with the name of a color built through macros

Consider the following code and especially the command \nicecolorname which builds the name of a color following the pattern ["nice"][shade][hue]. In its current name, the command \color is ...
Vincent's user avatar
  • 5,801
3 votes
1 answer
64 views

ifmtarg testing a macro that is empty?

The following code works as expected: \NewDocumentCommand{\checker}{m}{\@ifmtarg{#1}{empty}{not empty}} \checker{} % Prints "empty" \checker{x} % Prints "not empty" However, how ...
Vincent's user avatar
  • 5,801
3 votes
1 answer
139 views

Parse every character and transform it into a table column

I am trying to produce an array that will output most ascii characters in a given LaTex font. Currently, I have the following awful code that works: \documentclass{standalone} \usepackage[utf8]{...
Vincent's user avatar
  • 5,801
31 votes
4 answers
18k views

LaTeX v.s. Typst: What is TeX Community's Future Plan? [closed]

Recently I have become increasingly anxious about LaTeX being (possibly) surpassed by Typst due to its simplicity. This answer shows several edges of Typst over LaTeX. I have been arguing with one of ...
Teddy van Jerry's user avatar
2 votes
2 answers
86 views

LaTeX does not finish compiling (infinite loop, maybe) when I place multiple \tl_use commands inside the \bool_until_do loop

I am trying to retrieve data from a .aux file using expl3. I want to ignore the first line because it serves a different purpose (hence the \ior_str_get:NN \l_seccion_lista_ior \l_tmpa_tl). The ...
gxono's user avatar
  • 538
5 votes
4 answers
556 views

how can I write an inline hexadecimal value? [duplicate]

How do I write an inline "\0x" without having LaTeX put each value on a new line? "\0x" in C programing identifies a hexadecimal value. I would like to write an inline string of ...
j0h's user avatar
  • 171
0 votes
1 answer
242 views

Is there an alternative to using yap.exe for rendering dvi files within MikTeX?

I have used MiKTeX and the book document class for mathematics layout for more than 10 years with little trouble. The "build" command always runs successfully but, just recently, the "...
keith77777's user avatar

1
2 3 4 5
14