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
0 votes
2 answers
35 views

Difficulty when using \ifthenelse{\equal{ }} to determine tilde (~) status

I'm having to determine whether the tilde (~) character exists at the end of a string, but I am seeing differing results depending on the macro, e.g: \documentclass{article} \usepackage{ifthen} \...
user avatar
1 vote
1 answer
32 views

How to check for the presence of a tilde (~) at the end of a text string?

How do I get to 'true'? \documentclass{minimal} \usepackage{xstring} \begin{document} \IfEndWith{string~}{\textasciitilde}{true}{false} \IfEndWith{string~}{\textasciitilde{}}{true}{false} \...
user avatar
0 votes
1 answer
19 views

Error when passing a command to a command when using IfSubStr

I am trying to build a command "TEST" which uses IfSubStr from the xstring package. When using the command, I need to pass another command "ARGUMENT" which contains a figure* ...
user avatar
  • 3
1 vote
1 answer
52 views

Using a CSV File to Drive Custom Macro

Background I am trying to figure out why the attached MWE is not working. My custom macro reqUser works correctly when using the xstring both inside and outside of the csvsimple environment. The expl3 ...
user avatar
  • 115
6 votes
4 answers
712 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
2 votes
2 answers
59 views

Using \usepackage{tikz,xparse,xstring,fp} to create a lattice a lattice multiplication

\documentclass[tikz,border95=3mm]{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[case/.style={minimum width=2cm,minimum height=2cm,draw},line/.style={blue!10!gray,line width=...
user avatar
  • 425
0 votes
0 answers
43 views

Using \vec inside \StrSubstitute to simplify math notation

I'm using several different calculi (programming languages) in a work, and I'm trying to define a tool to simplify my notation for them by replacing text with the proper notation; as of now, I've been ...
user avatar
0 votes
1 answer
63 views

LaTeX3 Verbatim-Like Command Illegal in Argument

LaTeX cmd: Verbatim-like command '\checkboxYesNo' illegal in argument. I get the above message when I tried to migrate away from using tabu & xstring combination to tabularray & native LaTeX3 ...
user avatar
  • 115
1 vote
2 answers
64 views

write to file full expansion of command

I have an issue I want to resolve, maybe you can help me. When I compile the mwe the following happens: In the PDF you can see: (X/A)(Up/Down) In the file.txt write: (\frac {a}{x})(\frac {u}{d}) How ...
user avatar
1 vote
1 answer
31 views

Use of \xs_IfStringCase_i doesn't match its definition?

I thought I had created a pretty straightforward command but apparently it's not allowed. I suspect I'd need to add \expandafter somewhere, but I'm not sure (where). I'd like to understand why in ...
user avatar
  • 121
3 votes
1 answer
77 views

how to get value from a list by the index

I build a list by a macro to store some values. I wonder if there is method to get value by its index number from the list. The following code shows my intention. Code example: \documentclass{article} ...
user avatar
  • 2,435
1 vote
1 answer
71 views

LaTeX3 Text/String Comparison Replacement for xstring

Trying to update my college's LaTeX thesis class (for fun while I wait for the actual degree to show up). It hasn't been touched in a few years. Anyways, one of the commands it has is below: % TODO: ...
user avatar
  • 115
2 votes
2 answers
39 views

How to return a filename containing underscore from a switch-case function (like ifEqualCase) as a parameter into a function like addplot?

When plotting and iterating through a list of filenames, I wanted to call them from a switch-code and apply them in \addplot. I used the switch-function \IfEqCase from the xstring package. However, ...
user avatar
0 votes
1 answer
53 views

Automatically add section label based on file name

I am trying to automatically add section label based on the file name. My structure is as such: main.tex 1.0.introduction.tex 1.1.0.foo.tex 1.1.1.bar.tex I am using \currfilename from package ...
user avatar
  • 141
0 votes
1 answer
65 views

How to extract year from date in iso 8601 format?

I want to extract the year (or day or month) of a date which is stored as ISO 8601 in a database. My MWE looks like: \documentclass{article} \usepackage{xstring} \usepackage{datatool} \newcommand{\...
user avatar
0 votes
0 answers
79 views

How get the result of a macro that uses xstring functions before writing to a file

I encountered the need to write last name with initials (extracted from the full author's string based on first chars of first and middle name) into an external file. I use the xstring package to ...
user avatar
8 votes
3 answers
525 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
0 votes
0 answers
53 views

Detokenize input to \newcommand

I would like to define a command that removes .m when referencing to the caption generate_simdata.m (i have a lot of such matlab function files, and would like to reference them normally with \nameref ...
user avatar
0 votes
0 answers
31 views

Creating Modifiable Text

I was wondering if there was a way to create a string variable? I need to use a WHILE loop where I remove the first char of a string, and I need to have that saved. I tried other ways: to put the ...
user avatar
  • 1
3 votes
2 answers
359 views

Possible bug in xstring + pdfLaTeX

Question refined considering the replies… In macro \StrCut, if the first argument contains a “ç”, we get an error message. The same happens with ”\c{c}” or capital “Ç”. When replaced with a plain “c”...
user avatar
4 votes
1 answer
105 views

How to customize style of section and subsection numbers when used in headers?

TL;DR - Why am I getting errors with the last line of \usepackage{xstring} \renewcommand*{\thesection}{\alph{section})} \renewcommand*{\thesubsection}{\StrGobbleRight{\thesection}{1}.\roman{subsection}...
user avatar
3 votes
1 answer
50 views

StrGobble doesn't work with \numexpr

I made the following function which strips left, right or both (if present) brackets and it seems to work as intended when used in the document, i.e. \stripp{1}, \strip{(1)}, \strip{1)} and \strip{(1)}...
user avatar
  • 560
2 votes
1 answer
64 views

Use a command with variables that uses \IfSubStr on the lowercased value of the input variables

[Similar questions] I looked at \lowercase with \IfSubStr and \StrDel but the suggestions didn't work. I apparently may have expl3 since I can use \newcommand. [Issue] I want to pass a variable to a ...
user avatar
2 votes
2 answers
64 views

Splitting a string with xstring and using command on separated string

I want to split a string into two parts, the first letter in the first part and the rest in the second part. Then I want to convert the whole string to uppercase and write the second part in \...
user avatar
  • 829
13 votes
3 answers
367 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
0 votes
2 answers
39 views

How to use xstring predicates inside \includegraphics?

This is the code: \documentclass{article} \usepackage{graphics} \usepackage{xstring} \begin{document} \newcommand\abs[1]{\IfBeginWith{#1}{/}{#1}{images/#1}} \includegraphics{\abs{/tmp/photo.jpg}} \end{...
user avatar
  • 10.2k
3 votes
1 answer
107 views

How to extract the fontname from \the\font

I know LaTeX doesn't have strings as such but I want to be able to get and save the human readable version of the current font name. \f@family does not work as expected because it shows the base font ...
user avatar
  • 153
2 votes
2 answers
50 views

xstring: replace substring of text defined in macro

I'm not sure whether I've got the terminology right in the question title, but here's what I'm looking for. I'm trying to put together a class file that specifies the formatting requirements my ...
user avatar
  • 615
1 vote
2 answers
74 views

update counter in newcommand without printing the result of the command

In the following MWE I want to update my counter via a custom command \noofwords, but it writes an error on line 25: Missing number, treated as zero. \noofwords writes the PDF otherwise just fine the ...
user avatar
  • 455
0 votes
0 answers
63 views

Why does this \gappto cause "Missing \endcsname inserted"?

I have a macro recoding the language: \def\mylang{English} and a command to convert the language name into its abbreviation: \NewDocumentCommand{\StrToABBR}{m}{% \expandafter\lowercase{\...
user avatar
  • 6,566
8 votes
4 answers
357 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
0 votes
1 answer
53 views

Problem with argument expansion in xstrings \IfSubStr nested in package macros

Thanks for any suggestions on this problem. This is a variation on how to use xstrings to make a test when the xstrings test function is buried deep in code. I have read a dozen examples or more on ...
user avatar
0 votes
1 answer
36 views

Using output from a substring (xstring) conditional within a url (href)

Unable to pass output from a substring conditional into a URL: MWE: \documentclass{memoir} \usepackage{xstring} \usepackage{hyperref} \newcommand{\substring}{% \IfSubStr{% Physics,% Chemistry,% ...
user avatar
2 votes
2 answers
150 views

Conditional with multiple conditions, one of which is a string search

Aim I want a command to write "where #1 is an arbitrary constant", "where #1 are arbitrary constants", "where #1 is an arbitrary function of #2", or "where #1 are ...
user avatar
  • 715
4 votes
3 answers
86 views

Stackengine not working with xstring

I've been trying to make a command that allows me to automatically retypeset any V̇ in a given string, as in the font I'm using it typests as .V which isn't ideal. Using XeLaTeX I compiled this source ...
user avatar
1 vote
1 answer
77 views

xstring : \IfStrEq and macro as string

I don't understand how \IfStrEq from xstring works. Why this code doesn't show "This is text" ? \documentclass[10pt,a4paper,twoside]{article} \usepackage{xparse} \usepackage{xstring} \...
user avatar
5 votes
2 answers
97 views

How do I eliminate the space when doing \StrSubstitute repeatedly?

I'm working on a dictionary for a constructed language, and it has multiple orthographies (the relevant ones are one in Latin and one in Greek). For various reasons it's helpful to be able to convert ...
user avatar
6 votes
2 answers
154 views

Why does `xstring`s `\StrBefore` work, but not `\IfBeginWith`?

I'm currently using the package showkeys to debug the labels in my document. Using the command \renewcommand{\showkeyslabelformat}[1]{...} one can customise the display of the labels. I want to handle ...
user avatar
0 votes
0 answers
33 views

Can't use IfStrEqCase in caption? [duplicate]

\documentclass[]{article} \usepackage{xstring} \newcommand{\hyb}[1]{\IfStrEqCase{#1}{% {2}{$\sqrt{#1}$}% {3}{Hi}% % you can add more cases here as desired }[\PackageError{...
user avatar
  • 145
2 votes
2 answers
130 views

Drawing an old punched card using tikz

I am trying to draw a punch card using tikz. The card is a 8 x 80 matrix. A card "stores" a sentence (e.g. a line from a program's source code) printed in the card header via an encoding ...
user avatar
2 votes
1 answer
121 views

Help to make a faster token replacing macro

I have a macro called \logic which helps me write logical formulas faster by simplifying some common logical symbols. So when I write $\logic{p -> q}$ I obtain $p \to q$. Here's the code: \...
user avatar
  • 3,341
0 votes
1 answer
107 views

How to use xstring IfEq inside command?

I wrote a command for accessing a hardcoded string ("For Reasons™", because xstring StrMid is incredibly slow on large strings) and wonder now Why can the results be printed but not reused? ...
user avatar
  • 268
0 votes
1 answer
35 views

Having trouble with IfStrEq from xstring

precondition: The filename is lab00.tex \def\fn{\jobname} \StrLeft{\fn}{1}[\firstChar] \IfStrEq{\firstChar}{l}{true}{false}
user avatar
0 votes
1 answer
83 views

Iterating through CSV file - command viewed as one item

I'm trying to iterate through a CSV file, but am running into trouble. The file is multiple lines and I want to go through the CSV items one-by-item. When using the etoolbox docsvlist, it inerprets ...
user avatar
1 vote
0 answers
47 views

using xstring to obtain lead author's last name from authblk in a class file

I would like to query the last name of the first author of an article and then put it into the header. I use \StrBetween on the \AB@authlist macro to get the part of the string between the first space ...
user avatar
  • 56
8 votes
1 answer
403 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
1 vote
0 answers
27 views

Problem with IfStrEqCase? [duplicate]

I am using \IfStrEqCase to choose between various options within an environment. In the MWE below, if the line with the actions to be performed for any non-recognised option (\ifqsbreak{}.....\fi) is ...
user avatar
1 vote
1 answer
63 views

Character replacement does not work correctly

I am replacing a character. It works fine if I give that character as input directly. But when that character is extracted from a string, and then fed in to command for the reassignment it does not ...
user avatar
  • 167
2 votes
0 answers
69 views

Interpretation of Devanagari characters in XeTeX

\documentclass{standalone} \usepackage{fontspec,xstring} \setmainfont[Script=Devanagari]{Shobhika} \begin{document} \StrChar{abcd}{1} % Returns a \StrChar{क्ष}{1} % Returns क, but should ...
user avatar
  • 2,318
2 votes
2 answers
627 views

Manipulating \nameref title

I'm trying to create a new command that will act like \nameref but the output will manipulate the original name of what I'm referencing. To be more specific, I'll give an example: \documentclass{book}...
user avatar
  • 155

1
2 3 4 5
7