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
4k 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 ...
user avatar
  • 3,036
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 ...
user avatar
16 votes
2 answers
941 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. ...
user avatar
  • 70.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 ...
user avatar
  • 143
13 votes
3 answers
360 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 ...
user avatar
  • 387
12 votes
3 answers
741 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 ...
user avatar
  • 2,521
12 votes
2 answers
6k 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 ...
user avatar
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 ...
user avatar
12 votes
1 answer
498 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? \...
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{\...
user avatar
  • 7,787
11 votes
2 answers
1k 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 ...
user avatar
11 votes
2 answers
855 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 "...
user avatar
  • 181
11 votes
2 answers
484 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: ...
user avatar
10 votes
1 answer
409 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{\...
user avatar
  • 6,263
10 votes
2 answers
430 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 ...
user avatar
  • 53.5k
9 votes
3 answers
415 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 \...
user avatar
  • 8,302
9 votes
6 answers
917 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. ...
user avatar
  • 1,095
9 votes
3 answers
1k 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}{...
user avatar
  • 193
9 votes
2 answers
324 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 ...
user avatar
9 votes
4 answers
949 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 ...
user avatar
  • 2,555
9 votes
2 answers
1k 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{\...
user avatar
9 votes
1 answer
671 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 ...
user avatar
  • 1,303
9 votes
1 answer
831 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:...
user avatar
  • 341
9 votes
1 answer
288 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 ...
user avatar
  • 2,560
8 votes
4 answers
350 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 ...
user avatar
8 votes
2 answers
526 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 ...
user avatar
  • 729
8 votes
3 answers
304 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}% \...
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} \...
user avatar
8 votes
3 answers
202 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 ...
user avatar
8 votes
2 answers
1k 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{...
user avatar
8 votes
3 answers
466 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: ...
user avatar
8 votes
1 answer
387 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 ...
user avatar
  • 441
8 votes
2 answers
397 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 ...
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 ...
user avatar
8 votes
1 answer
636 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{\...
user avatar
8 votes
1 answer
471 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 ...
user avatar
  • 6,456
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 ...
user avatar
  • 12.7k
7 votes
2 answers
701 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 ...
user avatar
7 votes
2 answers
897 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 ...
user avatar
  • 5,571
7 votes
2 answers
425 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 ...
user avatar
  • 1,087
7 votes
1 answer
405 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/...
user avatar
  • 73
7 votes
2 answers
2k 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 ...
user avatar
7 votes
2 answers
191 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 ...
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 ...
user avatar
  • 53.5k
6 votes
4 answers
692 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 ...
user avatar
6 votes
4 answers
690 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 ...
user avatar
6 votes
4 answers
307 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 ...
user avatar
  • 63
6 votes
2 answers
697 views

\StrMid and \MakeUppercase problem

What's wrong with this: \documentclass{minimal} \usepackage{xstring} \begin{document} \newcommand{\cim}{c1095} \StrMid{\MakeUppercase{\cim}}{1}{1} \StrMid{\cim}{2}{100} \end{document} \MakeUppercase{...
user avatar
  • 1,206
6 votes
4 answers
433 views

Extracting characters of two strings in a for loop

I have two strings of equal lengths, let's say abc and def (in reality they can be much longer). Both strings consist only of letters a-z, A-Z (no numbers, no special characters etc.). I need to ...
user avatar
  • 13.2k
6 votes
2 answers
333 views

\uppercase does not work with \IfSubStr?

I'm using \IfSubStr macro of xstring package to decide if user given options contains some letter and if they do I take some actions. I want case independent test on whether user options contain ...
user avatar
  • 1,795

1
2 3 4 5
7