All Questions
Tagged with programming macros
123 questions
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*{...
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{...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
\...
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 ...
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 ...
1
vote
3
answers
84
views
Branch over number of characters of an argument provided to a macro
I currently have the following command:
\newcommand*{\setfontshape}[1]{\@ifnotmtarg{#1}{\csname#1shape\endcsname}}
that helps me produce the command: \scshape from text sc.
I would like to modify my ...
0
votes
0
answers
79
views
Automatically calculate years of experience from provided start/end dates
I'm very very new to LaTeX and not even sure if this is possible.
\resumeSubheading
{Undergraduate Research Assistant}
{6 Years \& 3 Months} % 1 <---------------...
0
votes
0
answers
137
views
Using external dependencies in my Latex main file
I'm using the package "snapshot" to generate a list of external dependencies of my filename.tex file. This list's result is stored in a filename.dep file.
The goal would be to use this ...
7
votes
2
answers
712
views
Why can't I use <some macro> inside the argument of <some other macro>?
I have some macro X and Y, which works well when used independently. However, when I try to put one inside another, it results in some error.
Why is that the case and how can I fix it?
Note: this is ...
1
vote
1
answer
162
views
Blackout censor macro capable of handling italic and bold fonts
In the following TeX stackexchange answer, the author provides an excellent \blackout macro that produces very aesthetically pleasing underline effect.
However, this macro does not work well with any ...
2
votes
1
answer
78
views
Macros that can scan the contents of their arguments
I was thinking that it since the architecture of LaTeX is a collection of pre-processors on top of TeX, that it may be possible that some macros could in theory do some sort of find-and-replace within ...
0
votes
0
answers
82
views
"Situation management" in LaTeX / expl3?
It happens from time to time that I would like to implement LaTeX commands that behave differently depending on the situation.
E.g., a command that returns different compositions of tokens depending ...
3
votes
1
answer
153
views
How to ignore contents of an environment imported from another file?
Consider the following scenario:
I define a package mypac.sty as follows
% mypac.sty
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{mypac}[2020/10/08 v0.01 LaTeX package for my own purpose] ...
0
votes
2
answers
1k
views
How do i force \pagebreak on everything in LaTeX
I would like to learn how to force a page break on everything that goes over the page. Suppose I have a document that involves multiple images, paragraphs, figures connected to paragraphs and lists. ...
5
votes
4
answers
487
views
How to command LaTeX to treat a non-value as 0
I have this command
\newcommand{\lines}[1]{\multido{}{#1}{\vskip 5mm \makebox[\linewidth]{\dotfill}} \vskip 8mm\setlength{\rightmargin}{5em}}
It allows me to create dotted lines with ease.
For ...
2
votes
1
answer
39
views
Optional savebox with options
I'm working on a modified version of the report.cls for internal documents that might have a standard disclaimer text included. Ideally, I'd like to have something like
\disclaimer{some category}{...
2
votes
1
answer
245
views
How add new argument to command to control scaling?
The following code, slightly modified from https://tex.stackexchange.com/a/552769/13492, allows creating new symbols \bigplus, \bigtimes, and \bigbox.
However, it hard-codes the scaling factor \...
1
vote
1
answer
49
views
Command works as "\csname cmd \endcsname" but not as "\cmd"
I'm trying to create a command (\dummy) for dynamic macro definition. It is supposed to return a macro that is named dynamically (#3) with the content of #2 concatenated after #1 iterations.
\...
1
vote
1
answer
54
views
How to use integer from one command into another?
I have following way to get number of spaces in a string
\ExplSyntaxOn
\NewDocumentCommand{\HowManySpaces}{ m }{
\seq_set_split:Nnn \l_tmpa_seq { } { #1 }
\int_eval:n {(\seq_count:N \l_tmpa_seq) ...
0
votes
0
answers
183
views
How can I create Local commands definitions in equations?
I would like to use small local macro expansion similar to how \newcommand works but on a per environment basis.
Something that would expand
\[
\begin{local}
\local{\poly}[2][x]{#1^2 - #1^#2}
\...
1
vote
1
answer
114
views
Convert string to one character with a hash table
I have a report where I mention some people. Sometimes I want to hide the real name of these people. I would like to write a macro that converts the name to a single character.
\name{John Doe} ...
3
votes
2
answers
320
views
modifying default tabular behaviour
I basically do all my tables the same way:
Is it possible to make tabular automate the \toprule, \midrule, \bottomrule and \hdashlines?
\documentclass{article}
\usepackage{booktabs,array,arydshln}
\...
7
votes
2
answers
2k
views
Macro for Automating Truth Tables
I used this truth table when writing a proof.
Unfortunately I made a tiny typo; The first time around, I misplaced an additional ʹ symbol, which just happened to make the output exactly wrong. It ...
0
votes
4
answers
203
views
How to define a macro that takes the definition of a macro as an argument
We would like to define a macro \ellipsis that takes four argument and has the following behaviour:
\ellipsis{x^{#DUMMY#}}{0}{5}{+}
and outputs:
the pattern string #DUMMY# (which doesn't have to be ...
1
vote
1
answer
92
views
Define a `\newenvironment` that stores its content in a token register or in a macro
In the code below I want to define a new environment that stores its contents in order to use it later several times with different formats
\documentclass{article}
\newtoks\environmentcontents
\...
1
vote
1
answer
103
views
writing functions and wrapping commands for abstraction
Can i write a little function (or macro or whatever) that wraps two commands (functions?) into one; united under a single alias?
Specifically I want to wrap \input{} and \includegraphics{} into a ...
6
votes
2
answers
244
views
Checking if argument is a floating point without breaking on control sequences in argument
Inspired by this answer to test whether an argument is a positive integer, I would like to extend this to floating point numbers. I want to have a macro \TestNumber that checks, whether its first ...
3
votes
2
answers
192
views
keyval - function for keyB should act dependent on value of keyA - how to do this?
I'm new to LaTeX. I learn and I use article class. I struggle learning working with keyval package:
I try to write macro \macro which only uses one mandatory argument where user can provide key value ...
1
vote
1
answer
416
views
Is there a way to define \xmat*{M}{n}{m} in the physics package
As titled, I want the command\mqty(\xmat*{M}{n}{m}) to generate a matrix like this:
$$
\begin{pmatrix}
M_{ 11 } & M_{ 12 } & M_{ 13 } & \cdots & M_{ 1m } \\
M_{...
1
vote
1
answer
898
views
Save command result in other command
I am getting a value by a command. Now I am temporarily changing a saved variable which changes the command output. After I finished some code I want to reset the stored value if the value before the ...
5
votes
4
answers
274
views
Unwanted spaces in user defined structures and the uses of % [duplicate]
This question arise from my recent activity on user defined commands of various kind. In the answer to a recently posed question, @egreg pointed out to me the importance of not forgetting a % after ...
2
votes
1
answer
141
views
expl3: lowercase sequence elements with line break breaks
I have some short text (book author names) stored in a sequence. Some author names are long, and therefore I have to insert manually a line break (\\). In a specific case, I have to typeset these ...
1
vote
2
answers
1k
views
Accessing a possibly undefined system environment variable from LaTeX (followup question)
This question is a followup to this thread in which @egreg provided a command \getenv to access a system environment variable. In response to my comment, he suggested a way to expand his script so ...
4
votes
2
answers
299
views
Overwrite default values of pgf keys
I defined a pgf key with a default value. In the following code I can overwrite its value in the default argument I created but I can't change the value using the pgfsetkeyvalue macro.
\documentclass{...
6
votes
2
answers
972
views
expl3: loop over a sequence with \int_do_while
I have a sequence where I get the elements by item number (needed for a macro don't show here). I am trying to iterate over the elements of the sequence in a do_while loop but I get an error about the ...
4
votes
1
answer
198
views
expl3: lowercase a token list inside a tikz node
This question ask for a variant of the answer to expl3: lowercase a token list given by Joseph Wright
I want to convert to lowercase a token list that is composed by letter, digits and the control ...
10
votes
2
answers
308
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.
\...
2
votes
1
answer
128
views
Programming with LaTeX -- Add names and characteristics [duplicate]
I have to do a lot of certificates and I have a list of names, every name has a characteristic (A,B or C). I have designed the whole structure for the certificate and have the 'name' and '...
4
votes
1
answer
102
views
Summing up values in an automatic generated table based on a meta tag
I am generating a table automated with a macro based on my other question (Time calculation with spreadtab).
There will be three (maybe four, maybe n - don’t know if the answer to this question can ...
6
votes
4
answers
575
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 to ...
7
votes
3
answers
5k
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 ...
9
votes
2
answers
1k
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 ...
5
votes
4
answers
437
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}...
7
votes
2
answers
83
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}
\...