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
1
vote
0answers
30 views

Xstring package bug?

Why is resultin equal to $\frac{1}{2}$ (tokenized)? Shouldn't result and resultin be equal? \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{...
2
votes
1answer
49 views

Efficiency of xstring (2e) vs. xparse (l3) in simple parsing

I understand string processing can be done on either LaTeX2e using xstring and expl3 using xparse (originally based on the 2013 thread "Tokenizing and parsing") I will be running a relatively simple ...
0
votes
1answer
26 views

Naming a section with filename

I am making quite a big document that will be worked on by many paople. We have therefore decided to divide the project by importing every section by it self as shown below. \import{Sections/}{Test} \...
1
vote
1answer
38 views

Automatically add parentheses if expression is composite

I'm trying to write a macro which automatically adds parentheses to an expression if the argument is composite. Specifically, I would like to define a command for the inner product of two vectors ...
0
votes
0answers
40 views

Conversion of a String to Integer [duplicate]

How can I convert a string of a small integer? In my code below, I check whether a string is a member of a list, which returns a string of "0" or "1". I am trying to use this returned value in \fpeval ...
1
vote
1answer
35 views

Simpler way to effect OR with two \IfStrEq?

Consider the pseudo-code IF mystring = "this" OR mystring = "that" THEN \dosomething ENDIF Is there a simpler way than the following to implement that (inside the \CheckString command)? In ...
2
votes
1answer
45 views

Using key option to package that uses string cases

What's wrong with the following package and source file? I get an error at line 14, after [Other], of mypackage.sty, and a "Missing \begin{document}" error resulting. The source: \documentclass{...
1
vote
1answer
42 views

adaptive math newcommand for indices

I have defined a command to add a star as the power to the input variable. It has to be in an adaptive way that if the input has indices, star is added to the main parameter and not the whole input. ...
5
votes
2answers
70 views

xstring fails to compare text containing \\

Using xstring in order to compare text containing \\ produces a compilation error. Here is my MWE: \documentclass{report} \usepackage{xstring} \makeatletter \def\Example#1{\def\@Example{#1}} \def\...
1
vote
1answer
19 views

Problem with testing suffix of \jobname, \c_sys_jobname_str

I have latex files with file names T-BA-DEC-de-0001_Title1.tex and T-BA-DEC-de-0002_Text2.tex. I would like to switch code depending on these file names. Up to now I tried to solve the problem using \...
2
votes
1answer
19 views

Substitute a space to a string to force tabular cell separation

I'd like to construct tables using macros to align syllables with other text. For that task, I defined a table with no separation between columns. This, however led to words being stuck together if ...
5
votes
1answer
133 views

How to compare a string to a cs from a read properly?

The scenario: reading a date in a yyyy-mm-dd form from a file to a cs. This cs later gets compared to a 'current date' macro to write a few args in a specific way to an external file. The current day ...
1
vote
3answers
57 views

Using \StrSubstitute in a macro definition

I would like to create a macro that typesets the argument using \emph and also creates a label with that name. My names contain underscores so I tried to use \StrSubstitute from the xstring package: \...
5
votes
3answers
117 views

Macro expansion inside \href

I want to make a shortcut for \href{tel:0123456789}{01\,23\,45\,67\,89} I can use \StrSubstitute from the xstring package as \StrSubstitute{01 23 45 67 89}{ }{\,} inside the second argument to ...
2
votes
1answer
73 views

Assigning a value from xstring

I'm trying to write some basic validation of user input to a command \noinsuit which takes two parameters, an integer in [0, 13] and a letter indicating the suit. So I expect \noinsuit{1}{C} to be ...
2
votes
1answer
78 views

How to expand condition on \IfEqCase before evaluation?

I'm trying to do a simple task (as in the MWE below). When a given text is given (a filename) it outputs a given color. To work as I intended, \IfEqCase should only evaluate the file extension, as ...
6
votes
2answers
59 views

Make a CSV out of a \IfStrEqCase list

I have a macro \DefineStrEqCaseMacro which defines a macro that selects a value based on a parameter. With this, I am trying to replace the manual method: \newcommand*{\SelectBasedOnValue}{beta}% ...
2
votes
1answer
157 views

Filling a table with list data: ! Extra }, or forgotten \endgroup

I'm trying to fill a table by iterating through predefined data and experience errors with both & (next column) and \\ (next row) using code like follows: \begin{document} % \foreach \s in \...
2
votes
1answer
52 views

Automatic index entry for multiword terms

I'm a lazy person. The less I type the better, so I'm trying to make a macro to automatically arrange index entries for multi-word terms (composed nouns actually). Normally you'd have to type: ......
3
votes
2answers
87 views

Use xstring to substitute reformatted names in strings

I would like to bold-face occurrences of strings conditionally on them occurring within longer strings, using the \IfSubStr and \StrSubstitute macros from the xstring package. The issue that I'm ...
4
votes
3answers
141 views

Detect empty or null output from xstring's StrBetween

I have some code for formatting names. However, the ifempty macro from xifthen is unable to detect empty/null output from xstring macros such as StrBetween. The same goes for the \equal {} method. How ...
2
votes
3answers
61 views

TeX capacity exceeded while nesting two commands from hyperref and xstring

I have wasted most of my afternoon on this one and can't figure it out. I have prepared an MWE that demonstrates the problem. In my \displaylink command I invoke \href{raw_url}{anchor} (from package ...
2
votes
1answer
39 views

How to get the last two digits of next year?

It seems I can't solve the problem by google. I want to get the last two digits of the next year. I googled that the two digits of this year can be get by \Year{\the\year} \def\Year#1{\def\yy@##1##2##...
3
votes
1answer
119 views

String operation creates error in pgfmathsetmacro

I am trying to reference the first character of a string within a pgfmathsetmacro, however, the macro \StrLeft from xstring, I believe, is not playing well with pgfmathsetmacro. Take the following ...
4
votes
3answers
94 views

xstring TeX capacity exceeded

I try to store the result of an xstring pagckage’s command in another command (or variable, I don’t care), to reuse it in another xstring’s command, as you can see in the following MWE: \...
4
votes
2answers
48 views

How to use & differently than normal inside an `align` environment?

I'm trying to write a macro to let me write logic formulae in a more natural syntax. I've come up with a working version which however has a problem when used inside align environments (and in tabular ...
0
votes
1answer
79 views

How to set color conditionally

Disambiguation. For tables and odd even row color, see if this search at Stack Exchange helps: https://tex.stackexchange.com/search?q=table+row+color Disambiguation. For just unilaterally setting a ...
0
votes
1answer
30 views

\StrSubstitute breaks when an argument contains a MathOperator

I'm using \StrSubstitute from the xstring package, and it appears that the .tex file does not compile if any of the arguments to \StrSubstitute contain math operators that I have declared with \...
0
votes
2answers
54 views

Multiple conditions in xstring

This is potentially a very noob question, but how could one use multiple conditions when parsing with xstring? The accepted answer that I'm linking below, shows how one can align complex numbers in a ...
6
votes
4answers
196 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 ...
0
votes
1answer
126 views

String manipulation in xstring

I'm trying to make a string manipulation by using xstring package. Fore example \myparam equals to this: 1.1 Optimal solution of RNASP But string functions doesn't work. For example \StrLeft{\...
1
vote
0answers
68 views

xelatex fails with “Undefined control sequence” when using \StrBefore [closed]

I am getting the following error when I run the command xelatex sj_mwe.tex: ! Undefined control sequence. \casecitation #1->\StrBefore {#1}{,}[\texttobold ] \...
1
vote
3answers
63 views

\newcommand to define a function such as \#1\colon\mathcal{#2}\rightarrow\mathcal{#3}

SX.](https://tex.stackexchange.com), I would like to define a new command, in this occasion I want to denote a function, as in the title of the question. My attempt \documentclass{memoir} \...
2
votes
1answer
111 views

Use shortframetitle for list of frames only when defined

I'm creating a list of frames for my beamer presentation as in my previous question, which works like a charm. If a framesubtitle exists, it will be put into the list of frames in favor of the ...
1
vote
1answer
54 views

\IfStrEqCase redefines #1

What is the meaning of #1, #2, etc in the optional parameter of \IfStrEqCase? This required me to use a ##1 instead of #1 within \pgfplotsinvokeforeach which I was not expecting. I would have ...
3
votes
1answer
74 views

Different results of xstring test with inputenc and fontspec

In the following MWE both tests are true on pdflatex and inputenc but the second test fails on fontspec and luatex/xelatex. Any chance to get this engine agnostic (both true)? \documentclass{article} ...
1
vote
2answers
302 views

Splitting Strings by Comma

I need to split a string by commas, and I haven't found an easy way to do it in xstring or xparse (although I may be missing something obvious). So if I say: \def\pleaseHelp{"I, am, confused"} What ...
0
votes
3answers
212 views

\newcommand for a function with one optional argument inside other optional argument

SX. In this case, I want to create a \newcommand named \fun for function. My problem arises when I use a \ fun command again with the name f (the letter f is widely used in my document) and avoid the ...
0
votes
1answer
36 views

Using a computed date with \printdate from isodate

I want to format a date using \printdate from isodate, but I want to compute on the fly the date I'm formatting. Both parts of this work individually: I can compute a date and I can format one, but ...
0
votes
1answer
61 views

Using \StrSubstitute inside \embedfile is not working

I'm using the following code: \usepackage{xstring} \usepackage{embedfile} %\newcommand{\underscorefix}[1]{\StrSubstitute{#1}{_}{\_}} <-- not working \newcommand{\underscorefix}[1]{#1} \embedfile[...
2
votes
1answer
55 views

Problems with StrSubstitute from xstring and hyperref

I am trying to define a label from a string with blanks to use with hyperref. But I get an error. The example below does not compile if the two lines with comments are uncommented. Is there a remedy ...
1
vote
1answer
69 views

Problem with xstring: IfEqCase case falls thru

In Xfer I read all chars of a string one by one, that are before a '\'. Trlt 'translates' these chars and outputs them. In the end the macros that ends the string are output. Problem If a '\' is ...
3
votes
1answer
44 views

Substitute string within lstinputlisting command

listings's package command \lstinputlisting should have the following syntax for filenames with underscores: \lstinputlisting[caption={a\_b.mat}]{a_b.mat}. I would like to automate the process of ...
4
votes
1answer
97 views

comparing substrings

I would like to get the following code running, but the second test fails with ! Argument of \@secondoftwo has an extra }. What do I miss? \documentclass{article} \usepackage{xstring,ifthen} \...
1
vote
1answer
61 views

change last character from parameter if it is '+' or '-'

i want to use the package xstring to create a new command to change the last character for example if i have 2+ i want to display 2 plus, if 2- then 2 minus , but if i have 2-3 then i want to ...
2
votes
2answers
109 views

nested uppercase command not working

I am trying to create a reliable command that turns the first character of it's input to uppercase. So far I have no success, especially since it needs to work when the inputstring contains commands ...
0
votes
1answer
437 views

biblatex package error: outdated xstrings package

I am having a hard time to get my latex running again, I am about to write a PhD thesis. When i compiled my current files, some packages were missing, but the on the fly installation took care of that ...
0
votes
2answers
56 views

How can I use IfSubStr in a loop or an optional argument?

I'm trying to define a command for use in a tikz picture that changes its appearance based on characters in an option string. Here's a simple example. I want either 8 or 15 lines drawn, depending on ...
4
votes
2answers
125 views

\newcommand with argument (cases) in macro within qrcode

This works \newcommand within qrcode. \documentclass{article} \usepackage{qrcode} \newcommand{\aaa}{test1} \newcommand{\aab}{test2} \newcommand{\aac}{test3} \begin{document} \qrcode[height=5cm]{...
5
votes
2answers
595 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 ...