Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [xstring]

provides macros manipulating strings of tokens. For a basic use, tokens can be alphanumeric chars, but the macros can also be useful for manipulating tokens

1
vote
1answer
36 views

adaptive math newcommand for indices

I have defined a command to add a star as the power to the input variable. It has to be in an adaptive way that if the input has indices, star is added to the main parameter and not the whole input. ...
5
votes
2answers
63 views

xstring fails to compare text containing \\

Using xstring in order to compare text containing \\ produces a compilation error. Here is my MWE: \documentclass{report} \usepackage{xstring} \makeatletter \def\Example#1{\def\@Example{#1}} \def\...
1
vote
1answer
18 views

Problem with testing suffix of \jobname, \c_sys_jobname_str

I have latex files with file names T-BA-DEC-de-0001_Title1.tex and T-BA-DEC-de-0002_Text2.tex. I would like to switch code depending on these file names. Up to now I tried to solve the problem using \...
2
votes
1answer
16 views

Substitute a space to a string to force tabular cell separation

I'd like to construct tables using macros to align syllables with other text. For that task, I defined a table with no separation between columns. This, however led to words being stuck together if ...
5
votes
1answer
129 views

How to compare a string to a cs from a read properly?

The scenario: reading a date in a yyyy-mm-dd form from a file to a cs. This cs later gets compared to a 'current date' macro to write a few args in a specific way to an external file. The current day ...
1
vote
3answers
53 views

Using \StrSubstitute in a macro definition

I would like to create a macro that typesets the argument using \emph and also creates a label with that name. My names contain underscores so I tried to use \StrSubstitute from the xstring package: \...
5
votes
3answers
105 views

Macro expansion inside \href

I want to make a shortcut for \href{tel:0123456789}{01\,23\,45\,67\,89} I can use \StrSubstitute from the xstring package as \StrSubstitute{01 23 45 67 89}{ }{\,} inside the second argument to ...
2
votes
1answer
53 views

Assigning a value from xstring

I'm trying to write some basic validation of user input to a command \noinsuit which takes two parameters, an integer in [0, 13] and a letter indicating the suit. So I expect \noinsuit{1}{C} to be ...
2
votes
1answer
57 views

How to expand condition on \IfEqCase before evaluation?

I'm trying to do a simple task (as in the MWE below). When a given text is given (a filename) it outputs a given color. To work as I intended, \IfEqCase should only evaluate the file extension, as ...
6
votes
2answers
55 views

Make a CSV out of a \IfStrEqCase list

I have a macro \DefineStrEqCaseMacro which defines a macro that selects a value based on a parameter. With this, I am trying to replace the manual method: \newcommand*{\SelectBasedOnValue}{beta}% ...
2
votes
1answer
118 views

Filling a table with list data: ! Extra }, or forgotten \endgroup

I'm trying to fill a table by iterating through predefined data and experience errors with both & (next column) and \\ (next row) using code like follows: \begin{document} % \foreach \s in \...
2
votes
1answer
37 views

Automatic index entry for multiword terms

I'm a lazy person. The less I type the better, so I'm trying to make a macro to automatically arrange index entries for multi-word terms (composed nouns actually). Normally you'd have to type: ......
3
votes
2answers
85 views

Use xstring to substitute reformatted names in strings

I would like to bold-face occurrences of strings conditionally on them occurring within longer strings, using the \IfSubStr and \StrSubstitute macros from the xstring package. The issue that I'm ...
4
votes
3answers
131 views

Detect empty or null output from xstring's StrBetween

I have some code for formatting names. However, the ifempty macro from xifthen is unable to detect empty/null output from xstring macros such as StrBetween. The same goes for the \equal {} method. How ...
2
votes
3answers
59 views

TeX capacity exceeded while nesting two commands from hyperref and xstring

I have wasted most of my afternoon on this one and can't figure it out. I have prepared an MWE that demonstrates the problem. In my \displaylink command I invoke \href{raw_url}{anchor} (from package ...
2
votes
1answer
36 views

How to get the last two digits of next year?

It seems I can't solve the problem by google. I want to get the last two digits of the next year. I googled that the two digits of this year can be get by \Year{\the\year} \def\Year#1{\def\yy@##1##2##...
3
votes
1answer
97 views

String operation creates error in pgfmathsetmacro

I am trying to reference the first character of a string within a pgfmathsetmacro, however, the macro \StrLeft from xstring, I believe, is not playing well with pgfmathsetmacro. Take the following ...
4
votes
3answers
82 views

xstring TeX capacity exceeded

I try to store the result of an xstring pagckage’s command in another command (or variable, I don’t care), to reuse it in another xstring’s command, as you can see in the following MWE: \...
4
votes
2answers
46 views

How to use & differently than normal inside an `align` environment?

I'm trying to write a macro to let me write logic formulae in a more natural syntax. I've come up with a working version which however has a problem when used inside align environments (and in tabular ...
0
votes
1answer
70 views

How to set color conditionally

Disambiguation. For tables and odd even row color, see if this search at Stack Exchange helps: https://tex.stackexchange.com/search?q=table+row+color Disambiguation. For just unilaterally setting a ...
0
votes
1answer
27 views

\StrSubstitute breaks when an argument contains a MathOperator

I'm using \StrSubstitute from the xstring package, and it appears that the .tex file does not compile if any of the arguments to \StrSubstitute contain math operators that I have declared with \...
0
votes
2answers
52 views

Multiple conditions in xstring

This is potentially a very noob question, but how could one use multiple conditions when parsing with xstring? The accepted answer that I'm linking below, shows how one can align complex numbers in a ...
6
votes
4answers
192 views

nesting macro identifying string length 1 using xstring ifthen packages

I would like to write a latex macro \p which given input X returns X or (X) depending on whether X has character length 1 or not. Moreover, I want to be able to nest applications of \p. E.g. I want ...
0
votes
1answer
111 views

String manipulation in xstring

I'm trying to make a string manipulation by using xstring package. Fore example \myparam equals to this: 1.1 Optimal solution of RNASP But string functions doesn't work. For example \StrLeft{\...
1
vote
0answers
64 views

xelatex fails with “Undefined control sequence” when using \StrBefore [closed]

I am getting the following error when I run the command xelatex sj_mwe.tex: ! Undefined control sequence. \casecitation #1->\StrBefore {#1}{,}[\texttobold ] \...
1
vote
3answers
55 views

\newcommand to define a function such as \#1\colon\mathcal{#2}\rightarrow\mathcal{#3}

SX.](https://tex.stackexchange.com), I would like to define a new command, in this occasion I want to denote a function, as in the title of the question. My attempt \documentclass{memoir} \...
2
votes
1answer
93 views

Use shortframetitle for list of frames only when defined

I'm creating a list of frames for my beamer presentation as in my previous question, which works like a charm. If a framesubtitle exists, it will be put into the list of frames in favor of the ...
1
vote
1answer
46 views

\IfStrEqCase redefines #1

What is the meaning of #1, #2, etc in the optional parameter of \IfStrEqCase? This required me to use a ##1 instead of #1 within \pgfplotsinvokeforeach which I was not expecting. I would have ...
3
votes
1answer
73 views

Different results of xstring test with inputenc and fontspec

In the following MWE both tests are true on pdflatex and inputenc but the second test fails on fontspec and luatex/xelatex. Any chance to get this engine agnostic (both true)? \documentclass{article} ...
1
vote
2answers
244 views

Splitting Strings by Comma

I need to split a string by commas, and I haven't found an easy way to do it in xstring or xparse (although I may be missing something obvious). So if I say: \def\pleaseHelp{"I, am, confused"} What ...
0
votes
3answers
174 views

\newcommand for a function with one optional argument inside other optional argument

SX. In this case, I want to create a \newcommand named \fun for function. My problem arises when I use a \ fun command again with the name f (the letter f is widely used in my document) and avoid the ...
0
votes
1answer
34 views

Using a computed date with \printdate from isodate

I want to format a date using \printdate from isodate, but I want to compute on the fly the date I'm formatting. Both parts of this work individually: I can compute a date and I can format one, but ...
0
votes
1answer
56 views

Using \StrSubstitute inside \embedfile is not working

I'm using the following code: \usepackage{xstring} \usepackage{embedfile} %\newcommand{\underscorefix}[1]{\StrSubstitute{#1}{_}{\_}} <-- not working \newcommand{\underscorefix}[1]{#1} \embedfile[...
2
votes
1answer
51 views

Problems with StrSubstitute from xstring and hyperref

I am trying to define a label from a string with blanks to use with hyperref. But I get an error. The example below does not compile if the two lines with comments are uncommented. Is there a remedy ...
1
vote
1answer
65 views

Problem with xstring: IfEqCase case falls thru

In Xfer I read all chars of a string one by one, that are before a '\'. Trlt 'translates' these chars and outputs them. In the end the macros that ends the string are output. Problem If a '\' is ...
3
votes
1answer
41 views

Substitute string within lstinputlisting command

listings's package command \lstinputlisting should have the following syntax for filenames with underscores: \lstinputlisting[caption={a\_b.mat}]{a_b.mat}. I would like to automate the process of ...
4
votes
1answer
79 views

comparing substrings

I would like to get the following code running, but the second test fails with ! Argument of \@secondoftwo has an extra }. What do I miss? \documentclass{article} \usepackage{xstring,ifthen} \...
1
vote
1answer
56 views

change last character from parameter if it is '+' or '-'

i want to use the package xstring to create a new command to change the last character for example if i have 2+ i want to display 2 plus, if 2- then 2 minus , but if i have 2-3 then i want to ...
2
votes
2answers
107 views

nested uppercase command not working

I am trying to create a reliable command that turns the first character of it's input to uppercase. So far I have no success, especially since it needs to work when the inputstring contains commands ...
0
votes
1answer
414 views

biblatex package error: outdated xstrings package

I am having a hard time to get my latex running again, I am about to write a PhD thesis. When i compiled my current files, some packages were missing, but the on the fly installation took care of that ...
0
votes
2answers
54 views

How can I use IfSubStr in a loop or an optional argument?

I'm trying to define a command for use in a tikz picture that changes its appearance based on characters in an option string. Here's a simple example. I want either 8 or 15 lines drawn, depending on ...
4
votes
2answers
123 views

\newcommand with argument (cases) in macro within qrcode

This works \newcommand within qrcode. \documentclass{article} \usepackage{qrcode} \newcommand{\aaa}{test1} \newcommand{\aab}{test2} \newcommand{\aac}{test3} \begin{document} \qrcode[height=5cm]{...
4
votes
2answers
507 views

Extract First Character (allowing for extra grouping)

I would like to extract the first character. Using xstring's \StrChar works fine for simple cases. However, when the paramter has an additional brace group, I need some expansion magic to get that to ...
0
votes
0answers
73 views

Why does this produce “missing \endcsname” error? [duplicate]

I need to dynamically create the name of a macro, where part of the name is based on the argument which needs to be capitalized beforehand. The following MWE illustrates my intention: \documentclass{...
1
vote
0answers
40 views

How to recursively use macros from xstring? [duplicate]

I don't understand why the following mwe throws an errow TeX capacity exceeded. I'm guessing there's some expansion issue, but my TeX knowledge is not enough to resolve it. \documentclass{article} %\...
2
votes
2answers
157 views

How to perform a replacement on a string before doing a \write?

I'd like to output LaTeX code to a file, with the caveat that all backslashes are doubled (ie, \ is replaced with \\). This output will be consumed by another program. I've adapted egreg's answer ...
4
votes
2answers
140 views

extract number from \jobname as counter

I want to use a part of the filename as a counter: First I try to use a variable as a counter: mwe_aa_03.tex: \documentclass{scrartcl} \usepackage[automark]{scrlayer-scrpage} \newcommand{\...
1
vote
0answers
44 views

Output plain ascii text to output file (expandable \IfStrEqCase with multiple matches)

This question is specfically about an expandable version of \IfStrEqCase (with multiple matches) as per Modified \IfStrEqCase with multiple matches per case. However, in case this is an x-y problem, ...
0
votes
1answer
117 views

Manipulating a \ref{} as a string

I want to use macros from xstring to operate on the string produced by a \ref{}. Specifically I have a macro that "pads" a decimal number so that it sorts lexicographically; in other words 12.9 ...
1
vote
2answers
78 views

How to define macros with xstring and pass them to other macros?

Is it possible to use the xstring package to pass the result of one macro into the definition of another macro? If it is not possible, is there another way to accomplish this with LaTeX? ...