All Questions
108
questions
4
votes
3
answers
183
views
How to substitute placeholders in string with arguments?
I'm writing a document in two languages using the macro \enzh defined as below:
\documentclass{article}
\newif\ifen
\entrue % comment out to switch to Chinese
\newcommand{\enzh}[2]{\ifen#1\else#2\fi}
...
4
votes
7
answers
432
views
Get string from within curly brackets
I have a function that takes a parameters with other commands. Then I split the parameter by a second command that is in the parameter. Now I need to get the parameter that is given to this command. ...
0
votes
1
answer
75
views
Loop Through Array of Strings (Actually an Array of Array of Strings, e.g. `{{black, ab}, {white, cd}}`)
I'm drawing stones on a Go (game) board with SGF coordinates (which I only managed to do from the the help people gave me on this question) like this \drawStoneFromSgfCoords{ab}.
However, there might ...
4
votes
3
answers
148
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
\...
1
vote
0
answers
157
views
LaTeX: How can I escape arbitrary text as a literal string? [closed]
I have a build system for my latex files that injects some environment variables into the latex file that is to be compiled.
Usually, the environment variables contain path to image files. So, a build ...
1
vote
3
answers
81
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
127
views
Is there a way to remove specific characters from argument of a macro?
Suppose we have a macro saying,
\NewDocumentCommand\foo{m}{#1}
When it eats an argument, I want it to print whatever is in the argument without specific characters.
For instance, I want to remove ...
0
votes
2
answers
42
views
Concatenating macro parameter and string adds unwanted space [closed]
I wanted do define a simple macro like the following:
\newcommand{\testcommand}[1]{
\includegraphics[]{pictures/#1.jpeg}
}
But this does not work because it adds a space between the argument #1 ...
2
votes
2
answers
192
views
Using \g@addto@macro in a loop
I am confused when using \g@addto@macro in a loop. My code is:
\documentclass{article}
\usepackage{ifthen}
\usepackage{newfile}
\usepackage{xstring}
\makeatletter
\DeclareRobustCommand\@initial[1]{#...
1
vote
2
answers
47
views
Using string to process a macro name using listofitems seems to fail
I am trying to process the name of a command using listofitems, but when I am using \string to convert that command it does not behave the way I think it would behave.
Here is a code to illustrate:
\...
2
votes
1
answer
72
views
A macro that takes in a variable that is a number, interprets it as a string, check if it has a plus sign, removes it, then stores it to the variable
I want to create a macro \foo that takes in a \newcommand variable that is a number, e.g., \bar where it's defined as
\newcommand{\bar}{<number>}
and interprets it as a string, then checks if ...
3
votes
3
answers
1k
views
Text/string variable
Is it possible to make a command or variable to store text and then later input it in the document?
Example
\text1{This is text from the text1 variable and it is added in here.}
\text2{This is some ...
0
votes
3
answers
476
views
How \string and \newcommand work?
I try to write a command that each notation can link to the first appearance. Consider a notations A and a vector B. Define a command that fun{'}=B' and fun{x}=B^{x} for x=/='. If I want to write B^(A)...
2
votes
1
answer
144
views
Input dynamically generated file name
The situation is a bit weird and actually an excerpt from a large task.
I want to remove the last two characters from the file name (\jobname) and input another file with a name with these-two-...
1
vote
1
answer
113
views
Command to change a string on the whole document [duplicate]
I was wondering if it was possible to use a variable within the document to quickly change a string. For example in my cover letter I want to insert the name of a different company but without ...