Skip to main content

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

Filter by
Sorted by
Tagged with
34 votes
6 answers
5k views

Censoring Curse Words with Grawlixes

Suppose that I would like to censor a curse word <word> using grawlixes, e.g. "What the #@$! are you doing?!" How can I define a command \censor such that \censor{<word>} results in a ...
void-pointer's user avatar
  • 3,166
18 votes
1 answer
2k views

How to include part of an external git hash as text inside a document?

This is my first time asking a question on a site like this. Please tell me if I should do something differently, thanks! I want to include a short version of the latest commit hash from git as a ...
Kess Vargavind's user avatar
16 votes
2 answers
1k views

Why can't I expand \ref*{} as a string?

In the following code, if you change \def to \edef the code crashes. Nor can you perform normal string operations or tests. Removing hyperref (and replacing \ref* with \ref) works fine with \edef. ...
John Kormylo's user avatar
  • 82.2k
14 votes
3 answers
4k views

Extract number from string and compare problem

I try to extract the year, month and day from a string and write different text depending on the given date. I thought I could use xstring and etoolbox, but I can'st get it to work. Here's the code ...
Tom's user avatar
  • 143
14 votes
3 answers
568 views

xstring - How to define a macro that removes final punctuation?

Is it possible to create a command to remove final punctuation from a sentence (here to simplify, just remove the final period)? Thanks to the xstring package, I can remove the final punctuation for a ...
Bastien's user avatar
  • 479
12 votes
3 answers
761 views

TeX capacity exceeded while parsing a date string

I'm trying to parse a date (say, a due date) in a DD-MMM-YYYY format, e.g., 06-May-2012 and create macros \dueday, \duemonth, and \dueyear. I use xstring's commands to extract the substrings. Then I ...
Ali Mehrizi's user avatar
  • 2,651
12 votes
2 answers
7k views

Upright bold greek with condition in math mode

Good day! I googled the whole stackechange, but was not able to find the answer. I'm quite new to Latex, so my approach is not proper. I try to define a macro, that should format greek letter as ...
Vladimir Ivannikov's user avatar
12 votes
2 answers
1k views

Comparing strings extracted from Jobname

I have some code that parses \jobname, but it's not working as expected. I've included a minimal example below where the file name is HelloWorld.tex. When I print the \jobname, it comes out as "...
Addlai's user avatar
  • 201
12 votes
3 answers
2k views

How insert a character at the begin of every line from a source code?

I'm writing a lecture with many source codes for example. The codes are stored in severus different files. I use listing and minted packages for formatting the sources. I would like add character at ...
Adolfo Correa's user avatar
12 votes
1 answer
518 views

Text being output when none should be

I am confused as to why the MWE below produces any black text. As the code is below, the output is: However, if you comment out the \IfStrEq line then it works fine and the black text goes away? \...
Peter Grill's user avatar
11 votes
4 answers
6k views

How to cut a section title in the header

I redefine my headers as in the following MWE: \documentclass[12pt]{article} \usepackage{xstring} \usepackage{fancyhdr} \fancypagestyle{monstyle}{% \fancyhf{} % remove everything \renewcommand{\...
Loic Rosnay's user avatar
  • 8,177
11 votes
2 answers
2k views

Replace every backslash in a string with a forwardslash

I would like to replace every backslash \ inside a macro (string) with a forwardslash /. The macro is intended to contain a filename in Windows notation which should be replaced by a valid (La)TeX ...
Thomas F. Sturm's user avatar
11 votes
2 answers
569 views

\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: ...
Peter Grill's user avatar
10 votes
1 answer
430 views

Using xstring macros in edef

I've tried to use \protect to make the following \edef work but no luck. Can it be done somehow? \documentclass{article} \usepackage{xstring} \begin{document} \def\abc{a,b,c} \edef\result{\...
masu's user avatar
  • 6,621
10 votes
2 answers
2k views

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{\...
Charlie Bucket's user avatar
10 votes
2 answers
468 views

How to process a list and ignore spaces?

This question is part of a new package: metrix. Typeset metric/prosodic symbols standalone and above syllables. I’m wrinting a new package and I need to process a list (using etoolbox at the moment ...
Tobi's user avatar
  • 57k
9 votes
4 answers
663 views

String replacement in math mode

Writing a path in a graph as $a-b-c$ will not typeset as nicely as $a\text{-}b\text{-}c$, so I'm trying to create a macro that performs some string substitution. I tried using xstring, but ...
Henning Koehler's user avatar
9 votes
3 answers
442 views

Command doing the same job as StrBefore but being expandable

I am looking for a command allowing me to get 3 as output if the input is 3.2. \StrBefore{3.2}{.} works fine for this purpose but is not expandable and I need to call it in another macro inside a \...
Ludovic C.'s user avatar
  • 9,008
9 votes
6 answers
1k views

How to replace characters from jobname?

I have a tex file with name Chap-Name_of_Section.tex and I running pdflatex on it. I want to set the title of my document automatically according to the file name. This could be done using \jobname. ...
ddas's user avatar
  • 1,245
9 votes
3 answers
2k views

Extract correct counter value of a reference

Somewhere in my document there is a theorem labelled theoremA that has the number 2.21. Later, I want to set another counter to that specific number 21. First, I tried \setcounterref{newcounter}{...
namsap's user avatar
  • 193
9 votes
2 answers
362 views

Is it possible to use \index{\command} inside a \DeclareDocumentCommand?

So I've been writing a book of sorts where I've used xparse to create some commands and environments. Now, when the thing is almost done, I realised a index would be great to have! One of the ...
Robin Möller's user avatar
9 votes
4 answers
1k views

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 ...
Geoff's user avatar
  • 2,637
9 votes
1 answer
715 views

Why can't I compare a string with \par?

First of all: the package xstring cannot recognize a \par as argument. When I for example do this: \usepackage{xstring} \def\apar{\par} \def\str{a string} \IfStrEq{\str}{\par}{% true part }{% false ...
Didii's user avatar
  • 1,323
9 votes
1 answer
928 views

xstring character comparison and \meaning

\documentclass[pdftex,a4paper,12pt,oneside]{book}% \usepackage{xstring} \begin{document} \newcommand{\tmpa}{} \newcommand{\tmpb}{} \newcommand{\tmpc}{} \renewcommand{\tmpc}{abcdefg} \noindent tmpc:...
pmks's user avatar
  • 341
9 votes
1 answer
327 views

Count the number of references containing substring in field

I have several references in a document. I'd like to display some statistics regarding the references - for example, citations with author Smith, citations between year xxxx and yyyy, citations ...
simont's user avatar
  • 2,790
8 votes
2 answers
623 views

Macro for integrals, a problem with limits

For a while now I have tried to come up with a macro, that can properly format inegrals (the way I like). Aswell as giving it a few options that can be chosen e.g. \int and \oint. So far there is a ...
Simon's user avatar
  • 893
8 votes
3 answers
312 views

xstring command in renewcommand

I'm trying renew \texttt command with condition on ending . or ,. But after making this: \usepackage{xstring} \let\OldTexttt\texttt \renewcommand{\texttt}[1]{% \OldTexttt{\hspace{0.4em}#1}% \...
Petr Přikryl's user avatar
8 votes
2 answers
3k views

Nesting of test commands (IfStrEq, IfSubStr etc.) of xstring

The following code does not work: \documentclass{article} \usepackage{xstring} \newcommand\checkempty[1]{ \IfStrEq{#1}{}{% Empty }{% NonEmpty } } \begin{document} \...
Stefe Klauou's user avatar
8 votes
3 answers
207 views

Generating a table based on a list and a number of columns

Sometimes a table is used to compact a large number of items. Example: a b c d e f g h j k l Instead of listing all items separately. We want to define a command that eases the implementation of ...
willeM_ Van Onsem's user avatar
8 votes
2 answers
2k views

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 wrong? \documentclass{article} \usepackage{...
User49582934's user avatar
8 votes
3 answers
1k views

String to lowercase and replace spaces with underscore

I am trying to convert a predefined string in a variable to its lowercase and replace the spaces to underscore. But it's not working. The new string after conversion is like this: ...
t.abraham's user avatar
8 votes
1 answer
546 views

Typewriter Animation with Math

A previous question inquires about animating some simple text, with an elegant solution that uses the animate package and the xstring package. Is there a way to alter this code so that it works in ...
Astor Florida's user avatar
8 votes
2 answers
410 views

Why are some macros undefined inside an if case?

I'm trying to check if a string is only of one char, and I ran into this problem: LaTeX complains that \StrLeft in the comparison takes and additional argument: ! Argument of \@secondoftwo has an ...
Henrik Hansen's user avatar
8 votes
2 answers
1k views

StrSubstitute for multiple replacements in a loop?

I am trying to replace multiple keywords using \StrSubstitute inside a loop using foreach - but unable to accumulate all the results. The result of each \StrSubstitute call is getting lost inside the ...
Gopalakrishna Palem's user avatar
8 votes
2 answers
3k 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 ...
Peter Grill's user avatar
8 votes
1 answer
670 views

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{\...
jamesthenabignumber's user avatar
8 votes
1 answer
561 views

Manipulate title field's strings in biblatex

I need to take the first string (considering First~Second a single string) from the title field from anonym entries and: Format this first string differently from the rest of the title, e.g.: LES ...
henrique's user avatar
  • 6,636
7 votes
2 answers
1k views

Replacing substrings by linebreaks

I have a LaTeX document with several authors that I enter like \author{First Author \& Second Author \& .... In some places in the document I want to print these authors with a linebreak ...
schtandard's user avatar
  • 15.5k
7 votes
2 answers
743 views

Using xstring to check .tex file name

I am having difficulty in using xtring to check the file name of the .tex file. All three of the cases shown below produce the wrong output. Surprisingly in my actual more complicated usage, the ...
Peter Grill's user avatar
7 votes
2 answers
3k 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 ...
Kevin Gregory's user avatar
7 votes
2 answers
1k views

Replacing ampersands in argument

I am trying to define a command which takes as an argument a string containing ampersands, and replaces every ampersand by a space. Following the ideas in Replacing characters in argument strings, I ...
yori's user avatar
  • 5,711
7 votes
2 answers
497 views

Illegal parameter when nesting commands

I keep getting illegal parameter errors when trying to define a command that contains another previously defined command. I know that you have to be careful with nested definitions, but I didn't think ...
DavidR's user avatar
  • 1,107
7 votes
3 answers
8k views

String comparison

\documentclass{article} \usepackage{xifthen, xstring} \newcommand{\IfOne}[3]{ \if\TokenIsIn#1 #2 \else #3 \fi } \newcommand{\IfTwo}[3]{ \ifthenelse{\equal{\TokenIsIn}{#1}}{#2}{#3} ...
Miheer's user avatar
  • 173
7 votes
1 answer
431 views

Undefined Macro in Package xstring

I have a very basic problem. I am trying to use the xstring package in a Latex document and I keep getting the following error message for an undefined control sequence: (c:/Program Files (x86)/PCTeX/...
JohnS's user avatar
  • 73
7 votes
2 answers
207 views

Applying and doing math on two functions read from a file using pgf

I'm trying to read two functions of x from a file, and then get the result of f(8) / g(8) using pgfmathparse. Here is a minimal (not) working example: \begin{filecontents}{data.dat} f(x) g(x) x ...
habs's user avatar
  • 173
7 votes
0 answers
6k views

MikTeX can’t find xstring [closed]

I’m not using MikTeX myself but someone I developed a class for. And it seems like there’s a problem with xstring. The following MWE compiles fine with my TeX Live 2012 but MikTeX (on Win 7) can’t ...
Tobi's user avatar
  • 57k
6 votes
6 answers
633 views

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 /...
Michel Charpentier's user avatar
6 votes
4 answers
850 views

What about "exotic" characters in xstring?

When I use the macro \StrLen on a string that contains one or more "exotic" characters, the value returned does not correspond to the actual number of characters in the string. I suspect ...
Jean-Louis Brabant's user avatar
6 votes
4 answers
769 views

How to match last substring

I am working on displaying source code for which I pass a path to a macro. Now I am wondering if it is possible using xstring or stringstrings to match from after the last delimiter, i.e. / to the end ...
Pieter Stroobants's user avatar
6 votes
4 answers
413 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 ...
RRRR's user avatar
  • 63

1
2 3 4 5
8