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
Questions tagged [xstring]
368 questions
11
votes
2 answers
\IfStrEqCase having problem with last optional parameter
It's been a while since I asked an embarrassing question, and am pretty sure this is another one of those: This code below attempts to use \IfStrEqCase from the xstring package and results in:
Runaway argument?
{document} \par \par \par…
Peter Grill
- 223,288
9
votes
2 answers
LaTeX macro for Wikipedia article link
I'd like to create a LaTeX macro that will auto-create a link to a Wikipedia page for me.
\usepackage{xstring}
\usepackage{hyperref}
% replaces the whitespace with '%20'
\newcommand{\urlwhitespacereplace}[1]{\StrSubstitute{#1}{ }{\%20}}
%…
Charlie Bucket
- 113
9
votes
4 answers
choose from a list with xstring
I want a command that does the following:
\variation{1}{aaa;bbb;ccc} ----> aaa
\variation{2}{aaa;bbb;ccc} ----> bbb
\variation{3}{aaa;bbb;ccc} ----> ccc
The string in the second input can be a list with as many ; as needed (perhaps none at all),…
Geoff
- 2,637
8
votes
2 answers
Substring of filename in LaTeX
For filename "DoctorStrange.tex", I want to print the substring "Strange" dynamically inside the file. The following command does not work; what am I doing…
User49582934
- 175
- 6
8
votes
1 answer
Trouble using xstring to edit input parameter strings
I am trying to use \StrDel to modify a parameter to use within a command. For example, say my .tex file contains:
\command{Word Anotherword}
and the .sty file I reference contains:
\newcommand{\dosomething}[1]{
\some{#1}
\thing{\StrDel{#1}{…
6
votes
6 answers
Delete string up to last slash
\documentclass{article}
\usepackage{xstring}
\begin{document}
\StrBehind[2]{/foo/bar}{/}
\StrCount{/foo/bar}{/}
\StrBehind[\StrCount{/foo/bar}{/}]{/foo/bar}{/}
\end{document}
I'm trying to delete /foo/ out of /foo/bar using xstring. The first line…
6
votes
1 answer
Formatting String in LaTeX Macro Containing Dollar Sign (\$)
I am writing a macro that formats strings based upon their values in a LaTeX report. I have run into an issue in which a string containing a dollar sign (\$) will result in an error. Here is a minimum working…
DrTRD
- 217
6
votes
1 answer
Substitute string in subscript
I want to define a command to shorten formula like this a^1,\cdots,a^n, using a placeholder (-) instead of index, the code…
Martin Wang
- 657
5
votes
2 answers
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\printExample{\@Example}
\makeatother
\Example{not \\…
4
votes
3 answers
LaTeX xstring \StrCut with macros
I've been trying to give some formatted input to \StrCut from the xstring package in a very complex code, and I've been getting an error.
Here is a MWE…
mberthet
- 113
3
votes
4 answers
How to replace character with newline?
xstring: I want something like this \StrSubstitute{abc,cde}{,}{\newline}, but it doesn't work.
Andreas Schneider
- 2,755
3
votes
2 answers
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 running into is related to expansion of the \makebold…
Adam Erickson
- 444
3
votes
1 answer
The \IfStrEq (from xstring package) does not work properly
I read a file line to \a. Say \a equals A Q B with a space before A and after B.
Then I use \StrBetween[2,3]{\a}{ }{ }[\itstr], so that \itstr equals Q.
Now \IfStrEq{\itstr}{Q}{true}{false} should be true, but it is not. Would you help me with this…
Naser
- 31
3
votes
1 answer
Flexible \IfStrEqCase statement
I am trying to use xstring's \IfStrEqCase to switch between cases. It seems to work fine except for the case where the parameter for the switch is a macro with an optional parameter:
\MySwitch{$\MyMacro[optional]{a - b}$}
The problematic line is…
Peter Grill
- 223,288
2
votes
1 answer
\StrSubstitute doesn't work on the string produced by the \ref macro
In this LaTeX code I attempt to replace the "(" in references, so that they would look like "x)", not "(x)":
\documentclass{article}
\usepackage{enumitem}
\usepackage{xstring}
\begin{document}
\begin{enumerate}[label=(\alph*)]
\item…
Flying Jay
- 121