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

learn more… | top users | synonyms

32
votes
6answers
2k 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 ...
12
votes
1answer
295 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? ...
11
votes
2answers
194 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 ...
10
votes
3answers
472 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 ...
10
votes
2answers
147 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 ...
10
votes
1answer
116 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. ...
9
votes
3answers
209 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 ...
9
votes
3answers
1k 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 ...
9
votes
4answers
4k 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 ...
9
votes
3answers
146 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 ...
9
votes
2answers
141 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 ...
9
votes
1answer
252 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: ...
9
votes
1answer
194 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.: ...
8
votes
3answers
174 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}% ...
8
votes
4answers
240 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 ...
8
votes
2answers
277 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 ...
8
votes
2answers
122 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 ...
8
votes
2answers
419 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 ...
8
votes
1answer
119 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: ...
8
votes
1answer
125 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 ...
8
votes
1answer
415 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 ...
7
votes
2answers
410 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' ...
7
votes
1answer
121 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 ...
6
votes
3answers
136 views

xstring test for numbers within a range

I'm working on a document command that has a variety of optional arguments for different results. I need to add an option that yields 'true' for an optional argument within a range of numbers, for ...
6
votes
2answers
562 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} ...
6
votes
2answers
404 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 ...
6
votes
2answers
242 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} ...
6
votes
4answers
98 views

Using MakeLowercase and StrSubstitute together

I'm using LaTeX and have a string that I want to remove underscores from, and convert to lower case (in either order). The individual steps work: \MakeLowercase{AB\_CD} \StrSubstitute{AB\_CD}{\_}{} ...
6
votes
2answers
433 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 ...
6
votes
1answer
303 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 ...
6
votes
2answers
122 views

xstring substitution with font commands fails in error

I want to substitute some spaces with normal font \dots in between name parts typeset in \ttfamily. Below example works except for the commented part which fails miserably with the error: TeX ...
6
votes
1answer
57 views

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 is \usepackage{xstring} ...
5
votes
5answers
1k views

Process a string with replacing and splitting

I have an input string like "123-45" or "1-3-5" or "2-4; 6-8" where the minus signed should be removed. This is easy with the xstring package. \StrSubstitute{#1}{-}{} The next step is to split the ...
5
votes
2answers
483 views

Feeding arguments to xstring macros

In Footnotes with automatic final period, the comment was made to provide the possibility to add a period . to a footnote conditionally, based on whether the footnote already has a period or not. I ...
5
votes
2answers
120 views

How to use xstring commands in biblatex DeclareFieldFormat?

I'm trying to tweak a biblatex bibliography. One problem is the rendering of entries with eprint fields. Sometimes, I have something like eprint = "hep-ph/0207124", sometimes its ...
5
votes
2answers
161 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 ...
5
votes
2answers
87 views

Passing value to \bibleverse

Please help me to find out, how to pass a value to a command, which has additional arguments enclosed in (...). \usepackage{bibleref} \usepackage{xstring} \begin{document} \bibleverse{Gen}(9:9) ...
5
votes
2answers
1k 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 ...
5
votes
1answer
164 views

Substituting strings only when not bounded by letters or numbers

Using StrSubstitute from xstring I can find and replace matches. For e.g.: \StrSubstitute{I like to eat fish.}{fish}{apples} gives "I like to eat apples." \StrSubstitute{Do you want to ...
5
votes
1answer
82 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} ...
5
votes
2answers
80 views

How to choose from a list for using result in \ref?

Recently, in choose from a list with xstring, Geoff was asking about defining the command \variation that does the following: \variation{1}{aaa;bbb;ccc} ----> aaa \variation{2}{aaa;bbb;ccc} ...
5
votes
1answer
128 views

\IfSubStr does not work when used as parameter of another macro

It seem that if macro \IfSubStr from package xstring is used as parameter it is not expanded like other macros are. Here is minimal demonstration: \usepackage{xstring} \newcommand{\copyArg}[1]{#1} ...
5
votes
2answers
207 views

Transforming string into tabular row

Trying to have a command converting a string into a (tabular) row, where each cell of the row is (a function of) each character of the string. (\tilerow is my attempt, \tiletext is just for ...
5
votes
1answer
642 views

Generate labels using xstring and \Makelowercase

I am trying to write a command that allows me to reference a subsection with a generated label. The idea is that when I declare a step \step{Long Name With Many Uppercase Letters}, the generated ...
5
votes
1answer
137 views

StrSubstitute and @ inside and outside \lstnewenvironment

While further working on code for my answer to Different approach to literate programming for LaTeX, I am encountering a problem to which I am sure there is a very simple solution, but it completely ...
5
votes
1answer
163 views

Forcing the first choice of an newtcblisting environment

I have created a new environment based on "tcblisting" from package "tcolorbox" is code (MWE) is as follows: \documentclass[10pt]{article} \usepackage{tcolorbox} ...
5
votes
1answer
169 views

How to best split long strings?

I would like to do a simple \StrSplit (from the xstring package) on a string I have, however, the string in question may contain a \par, and it appears that \@xs@StrSpl@t@@, which I can only imagine ...
5
votes
0answers
1k 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 ...
4
votes
3answers
760 views

Misplaced \omit and \multicolumn in \IfEqCase

I have the following code with a command that creates rows for a tabular: \documentclass[letterpaper,10pt]{article} \usepackage[utf8]{inputenc} \usepackage{xstring} \newcommand*{\condrow}[2]{ ...
4
votes
2answers
67 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 ...