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

4
votes
1answer
37 views

Ignore undefined key in argument (it's defined in the macro before it's used)

How can I make this macro initially ignore the undefined key fn-special-text in the second argument? It is defined within the macro (because the name is generated from the text of the first argument; ...
5
votes
2answers
35 views

footnote inside a tested string

I would like to create a footnote within a command that tests the parent string (using xstring), such as: \documentclass{article} \usepackage{etex} \usepackage{xstring} \begin{document} \...
1
vote
1answer
40 views

How to exclude math environments from string replacement?

I would like to have a command which applies another command to each line of the input. My approach is the following simple string replacement: \documentclass{article} \usepackage{xstring,xparse} \...
4
votes
2answers
37 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
94 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}{...
5
votes
2answers
144 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: \documentclass{article}...
8
votes
1answer
254 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 ...
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
87 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
28 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
50 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} \begin{...
1
vote
2answers
45 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
16 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 option,...
2
votes
1answer
53 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
125 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 ...
5
votes
2answers
84 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 work:...
8
votes
2answers
72 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
75 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
50 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 ...
1
vote
2answers
74 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
2answers
85 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 ...
6
votes
2answers
494 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 ...
1
vote
1answer
164 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 ...
4
votes
3answers
91 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} \usepackage{...
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
1answer
49 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
97 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
43 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
53 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 %\usepackage[arial,utf8]{...
3
votes
1answer
179 views

Biblatex ibid in lowercase if prenote is present

I've defined my own biblatex style (see MWE) which uses citations in footnotes. I've patched the prenote command, because otherwise biblatex writes the prenote text in lowercase (note: I don't want to ...
3
votes
1answer
91 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
115 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
90 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
76 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
157 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
68 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 datatool:...
1
vote
1answer
29 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
102 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
104 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
69 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
50 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
189 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 "...
5
votes
3answers
129 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): \...
4
votes
1answer
141 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{% *[...