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

1
vote
0answers
8 views

Detect first character in list with macros

I have a comma separated list that I process with \foreach. This has been working for quite some time. Decided to make a minor tweak and that is to allow for an optional leading * in which case I want ...
7
votes
3answers
84 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 ...
5
votes
2answers
137 views

Unexpanded string replace

This question is related to Carry out substring replacement on variable's contents. Is it possible to perform string replace on an arbitrary string, without expansion? MWE: ...
4
votes
1answer
47 views

How can I determine the size of an array containing macros with optional parameters?

I am using my solution from How can I determine the size of an array? to count the number of entries. However, the \foreach/\IfStrEq in \SetArrayLength seems to have a problem when an entry is macro ...
7
votes
3answers
81 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} ...
1
vote
1answer
27 views

converting file: url to path

I am creating LaTeX files using a template engine. The problem I am running into is that the template engine is designed for generating web pages and generates URLs for external files, such as images. ...
4
votes
2answers
49 views

How to use \nameref with xstring package to check string length

I need to measure a number of characters in string, that I returned from label through \nameref command. Here is my MWE: \documentclass{article} \usepackage{hyperref} \usepackage{xstring} ...
1
vote
2answers
42 views

Use numbers stored in a command by spreadtab

My aim is to create a command to store numbers and calculated in the table. \begin{table}[h] \npthousandsep{,} \STautoround*{0} \begin{spreadtab}{{tabular}{| l | r | r | r |}} \hline ...
1
vote
0answers
15 views

transform variable-content to verbatim-like representation inside a newcommand (used then as optional argument)

I spend 8 hours in solving this, made some progress but now face the enormous difficulties with verbatim stuff in latex. Any help would be great! My aim: the todonotes package offers an inline ...
2
votes
1answer
50 views

Truncate parameter before newline

I want to truncate (cut/shorten) a string that contains newline (\\ or \newline) in such a way that only the first line remains. My problem is, that I use the todonotes package and have command ...
2
votes
1answer
37 views

How can I implement xstring's \IfBeginWith equivalently in a non-user-level macro?

I have a string check macro \IfBeginsWith from xstring that is wrapped in a non-user level macro. I have learned here that the wrong approach would be to use user-level commands in a wrapper that no ...
5
votes
2answers
82 views

\lowercase with \IfSubStr and \StrDel

I'm trying convert an argument to lowercase, strip out the spaces, and then search for the resulting string in a list. Thus far, I've had no luck. Here's the code I would instinctively expect to ...
5
votes
2answers
120 views

Multi-substring replace

I'm attempting to automate Werner's answer to my question here. In short, in order to sort the Norwegian letters Æ Ø Å (they come at the end of the regular Latin alphabet) correctly dtlsort needs ...
8
votes
2answers
71 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 ...
3
votes
1answer
74 views

How to test if two macros have identical definition

I want to test if two macro have identical definition. My naive attempt to use \detokenize does not seem to work in this simple case. However, I have used a similar approach before and it seems to ...
3
votes
1answer
47 views

truncate headings when they have macros in them

EDIT: @egreg, I copy-pasted your document with \expandonce, but if I put a subsection with a macro inside, \subsection{\textit{EE} LEFTshort subsec}, then I get the error Missing control sequence ...
2
votes
2answers
83 views

get part of the filename in the file content

I would like to print only the characters between Ch and - in the filename, so I use the packages currfile and xstring. As example : \StrBetween[1,1]{\currfilename}{Ch}{-} should gives 2 or 14 if ...
1
vote
1answer
145 views

Convert numbers in string to string

I store some strings in a variable \def\nomVAR{A12Z4E} and I want to create some other command using the content of \nomVAR. LaTeX doesn't accept to declare variable with number in its name. So the ...
1
vote
2answers
63 views

Language detection and condition

My problem is quite simple. I use the babel package and depending on the language I want to display something with respect to the active language. Therefore I use the package xstring. My code is the ...
2
votes
1answer
24 views

Defining command \file#1 and use it with \input command, and counter \thefile#1

I would like to define a command as \file#1 in order to use it with \input{\file#1}, where #1 is a entry given, as well as counter \thefile#1 The MWE is the next code \documentclass{article} ...
4
votes
3answers
88 views

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 : \documentclass[a4paper]{article} ...
4
votes
1answer
48 views

Problem with pdfstrcmp

i'm trying to store a three-digit parameter (101) in three different variables by using substrings. Depending on the input, i want to put one to three different icons in the upper right corner of an ...
2
votes
1answer
89 views

When using \IfEq to compare strings, is it one of those times when I should use an expandable xparse command?

I recently asked How can I migrate commands and environments from LaTeX2e to LaTeX3? [XeTeX] While that question is good, the answer is likely quite complex and would take a some time to effectively ...
2
votes
1answer
36 views

Problem with \IfStrEqCase combined with \StrChar

Upon compiling this minimal example \documentclass[12pt]{article} \usepackage{xstring} \newcommand{\digit}[1]{ \IfStrEqCase{#1}{% {0}{zero}% {1}{one}% {2}{two}% ...
2
votes
1answer
52 views

Case Sentence With xstring

I have a LaTeX document that gives me the following error: ! Argument of \@xs@IfStrEq@@ has an extra }. The document is as follows: \documentclass{article} %PAQUETES ...
3
votes
1answer
87 views

TiKz for each iteration over spaced string argument has an extra }

This is an example of the functionality of a macro, that should the following: iterate over a spaced string and print the first letter of each part. \newcommand\text{\StrSubstitute{a b c}{ }{,}} ...
4
votes
1answer
109 views

Carry out substring replacement on variable's contents

Say I have a variable that contains some non-plain text, for instance \def\var{Caro \textit{et al.}}, and I want to make a substring substitution of Caro for \underline{Caro}. If I try to follow the ...
3
votes
1answer
63 views

How to get xstring methods variables work with pgfmacros and vice versa in all situations?

I am trying to draw simple graph with my command: \documentclass{article} \usepackage{tikz} \usepackage{xstring} \usepackage{float} \begin{document} \newcommand{\lT}[4]{ \draw[line cap=round, line ...
3
votes
1answer
88 views

Character replacement in unicode string

I need a command to replace (erase) the characters · and | from a string. Consider the following naive code: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} ...
3
votes
2answers
74 views

Formatting Strings in Dynamic Variables with xstring

I need to format a string resulting from a dynamic variable set in a separate program for a LaTeX generated report. In particular, if a variable has a negative value (starts with a minus sign), I ...
5
votes
2answers
152 views

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 ...
1
vote
1answer
66 views

How to use variable in function call

I get data from a csv file using the datatool package: DTLgetvalueforkey{\thenames}{NAMES}{data}{BD}{#2} \ifthenelse{\equal{\thenames}{\dtlnovalue}}{}{ \specialtext{\thenames} } based on ...
1
vote
1answer
27 views

Store the result of IfSubStr and then count with StrCount

I want to store the result of IfSubStr (from package xstring) for using it later. So I define a command and I redefined with the result of IfSubStr. So far, so good. But now I want also to use ...
3
votes
1answer
96 views

List separated by semicolons, ending with a period

I am using a university-developed document class for my thesis. This class has the command \keywords which takes a list of \key commands and this is printed out as a keyword list after the abstract. ...
3
votes
1answer
61 views

StrChar causes error when used inside tikzpicture

The following TikZ code attempts to make a graph by drawing vertices 1 through 6, then drawing edges from the list. The edges are formatted as 12, 23, etc., so the command StrChar from package xstring ...
2
votes
1answer
98 views

Comparing strings in a class file

I am modifying a correctly functioning class file to add some capabilities. I need to compare two strings - a) \@stringtextfromuser and b) ABC. I have loaded etoolbox, and xtsring and have tried ...
0
votes
1answer
66 views

Xstring Problem with Ş

I want to use xstring version 1.7. However ş and ç cause problems. For instance \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{xstring} \begin{document} \StrSubstitute{ş}{a}{b} ...
4
votes
2answers
83 views

How can I use XString to count characters in a string with the “wrong” catcode?

I created a TikZ coordinate system to solve a positioning problem I had. The code is presented below. However, the code doesn't work; if you run it, you will get the Too many .'s error message ...
3
votes
1answer
49 views

Refering to colors using numbers

I want to create a command allowing me to colour arbitrary text with a color designed by a number (e.g. 1 = Green, 2 = Blue, etc). To that purpose, I create a first command, giving the name of the ...
6
votes
4answers
210 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 ...
3
votes
1answer
46 views

Using xstring with translator

I wrote the following code to extract the first letter of weekdays, as provided by the translator package: \documentclass{article} \usepackage{xstring} \usepackage{tikz} \usetikzlibrary{calendar} ...
7
votes
2answers
186 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 ...
4
votes
1answer
135 views

Passing escaped special characters for use as a URL through macros

From an earlier question on Escaping special characters for use as a URL, using \string to escape the special URL characters in the second example works great: \DefineMyFormatLinkParameters{% ...
5
votes
3answers
126 views

Issue: string manipulation with links inside

I have defined a new command \openintro which I call at every chapter of my work. This command basically constructs a lettrine sentence, like the image below (don't bother with text style): ...
6
votes
5answers
365 views

How to get the number of occurrences of characters in a string

How to get the number of occurrences of characters in a string? \documentclass[14pt]{extarticle} \usepackage{xstring} \usepackage{forloop} \usepackage{ifthen} \usepackage{pgfkeys} ...
4
votes
2answers
170 views

Active spaces with xstring's StrSubstitute

I have some text that I would like to preprocess using xstring's \StrSubstitute method (basically replacing certain keywords by simple commands such as foobar by \emph{foobar}). There are two side ...
0
votes
1answer
135 views

Get first letter of the document title

I'm trying to get the first letter of the document title, but I'm not getting. I'm using a code as: \usepakage{xtring} \StrLeft{\thetitle}{1}[\firstletter] Result of compilation: Undefined control ...
2
votes
2answers
61 views

Functions not working well together

I'm developing a interface for setting and changing distance parameters for a package. These distances are stored as strings so that the user can specify them in em and ex units if they want and ...
4
votes
2answers
94 views

Delayed expansion of StrSubstitute argument with active characters

This is an extension of my previous question. The accepted answer provided a way for me to delay expansion of a marked-up easylist list until the string was processed inside the environment. I'm ...
4
votes
1answer
69 views

Command doesn't expand into other commands after string substitution

The MWE should explain it all (use LuaLaTeX): \documentclass[11pt]{memoir} \usepackage[T1]{fontenc} \usepackage{fontspec} \usepackage{xstring} \usepackage{easylist} \begin{document} ...