Questions tagged [strings]

{strings} are sequences of characters (most commonly literal constants). However TeX doesn't have the same concept of strings as other languages, so for questions regarding text in general this tag does not apply. Usually when dealing with {strings} one also uses the primitive {pdfstrcmp} or dedicated packages, such as {xstring} or {expl3}'s string module (l3str).

Filter by
Sorted by
Tagged with
2
votes
3answers
37 views

How to check if the argument to a macro is a specific string?

I need to be able to pass [ ] (brackets with space in between) to a \def and check whether the \def's parameter contains [ ] (rather than something else). \begin{document} \def\bptoks{[ ]} \def\bpdef#...
1
vote
1answer
58 views

Conditional string replacements in LuaLaTeX

I want to process whole tex file content with string replacements using lua. The following are the conditions F, G, H should be replaced by P, Q, R respectively. However if they aren't followed by a,...
3
votes
1answer
29 views

Is it possible to use the `substr` package to extract the name of a command, then call that command?

Is it possible to use the substr package to extract the name of a command, then invoke that command? For example: \newcommand{\abc}{yay} \csname \BeforeSubString{|}{abc|def}\endcsname What I want ...
0
votes
0answers
27 views

Comparing a macro against a constant string in base LaTeX/TeX

Very often, I will have a macro that is one expansion away from a string that I would like to compare against a constant string. Now yes, obviously, I could simply define a macro that expands to the ...
2
votes
1answer
36 views

Bar graph with bars containing boxed strings

I have a .csv table containing both categorical and numeric data. The first column contains the categories, which are expressed as strings. The second column contains the number of observations that ...
1
vote
1answer
26 views

Missing spaces in conditionals

I'm trying to print two different text if a string contains a ',' or not. The conditional is working, but the text is getting printing without spaces. This is the code for the command: \...
10
votes
3answers
206 views

Smart-expansion of a range to a list of numbers

I am wondering if there is a simple way to expand some input text such as "3-7" as "3,4,5,6,7"? For context, I am using \foreach and want to be able to write \foreach \x in {3-7, 9, 14, 52} and ...
27
votes
2answers
10k views

How do I split a string?

I need to split a string into one or more substrings. I know that I could use the xstring package, but I'd like to do it using only inbuilt TeX/LaTeX commands. So, if I say \def\MyTeXKnowledge{Not ...
1
vote
1answer
27 views

Check if two comma separated lists have at least one common part

I am trying to do conditional exports based on the jobname. What I've got so far: \def\defaultexport#1{\gdef\@defaultexport{#1}} \newcommand\setdefaultexport[2][main]{ \edef\@jobnameextracted{\...
3
votes
3answers
59 views

how do I test for a unique string with multiple possibilities?

I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex. ...
1
vote
1answer
30 views

Compilation error when string testing using csvsimple

Consider this minimal working example: \documentclass{beamer} \usepackage{csvsimple,filecontents} \begin{document} \begin{filecontents*}{data.csv} id,type 1,a 2,b \...
5
votes
3answers
178 views

How do I unravel apparent recursion in an edef statement?

The text book that I'm writing requires the ability to dynamically build an alphabetically sorted list. As to not invoke the overhead of high powered, general purpose packages, I have opted instead to ...
8
votes
3answers
756 views

Replace characters in string based on preceding and following character

The following two strings are the result of the expansion of a biblatex citation command: Unicom Computer Corp. (in re), 13 F.3d 321, 30 Collier Bankr. Cas. 2d 655, 25 Bankr. Ct. Dec. 152 (9th Cir. ...
1
vote
1answer
18 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 \...
5
votes
2answers
98 views

Test whether a string is in a list with variable

Based on this question, I'd like the following \newcommand{\word}{Paul} \newcommand{\butnot}{Joe} \IfStringInList{\word}{George,John,Paul,Ringo}{Beat it}{Roll it} \IfStringInList{\butnot}{George,John,...
2
votes
2answers
64 views

How to use a string to form the name of an existing command?

In my project, I already have a file containing commands for names of my documents : \newcommand{\docOne}{Title of my first document} \newcommand{\docTwo}{Title of my second document} ... I've also ...
6
votes
3answers
304 views

Visualize multiple string segments

I need to compactly visualize multiple, possibly intersecting string segments for a given string. For instance, here is pseudocode for all palindrome occurrences in a binary string: S = 1 0 1 0 0 1 0 ...
3
votes
3answers
82 views

Append unique characters read from filecontents to a string

I have a list of 2-character strings that is read from table, e.g. \begin{filecontents*}{attributetools.dat} Attribute SL SK MC SL AA PT SK UP MC \end{filecontents*} I want to create a string that ...
30
votes
3answers
73k views

\uppercase in \newcommand

I tried to use \uppercase in \newcommand: \newcommand\universidad{My University} \newcommand\Universidad{\uppercase{\universidad}} When I use it I get this, My University and not, as expected, ...
25
votes
3answers
5k views

Extract first & last characters of macro argument?

In LaTeX, how do I extract/isolate/determine the first and last characters of a macro argument? Specifically, in the case I'm dealing with, the argument happens to be a base-10 integer (call it N). ...
11
votes
2answers
1k views

How to repeat over all characters in a string?

I have a command that formats a single character, let's call it \d{}. (In my case, \d{} adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts). I want to define a ...
1
vote
2answers
61 views

LuaLaTeX: Extract basename from path

My question is closely related to LuaTeX: Split path string for use in macros. However, in contrast to this, I would like to have the basename. For example, I am interested in file from /path/to/file....
6
votes
3answers
3k 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} ...
3
votes
2answers
95 views

How do I stop matlab-prettifier thinking print strings are comments?

I am trying to put my code into a Latex document using matlab-prettifier. I am doing this by using \lstinputlisting[style=Matlab-editor]{Trap.m}. An example of Trap.m (a MATLAB file) is as follows ...
0
votes
0answers
14 views

How to highlight C/C++ header file names with the listings package? [duplicate]

C/C++ header files can be given in two forms: <foo> or "foo". For example: #include <iostream> #include "myheader.hpp" By default, listings does not recognize the first form, and regards ...
0
votes
0answers
25 views

LaTeX - Pass variable into a string [duplicate]

In LaTeX I am trying to pass a variable into a line for the \progressbar. If you type everything in it looks like this \progressbar[linecolor=blue, filledcolor=green]{.25} \begin{picture}(0,0)\put(-...
1
vote
4answers
136 views

Stringify input - \string on token list

This is a problem I came across and I couldn't find an answer to it on the web so I'm going to do an Q&A-style post here. The problem With the tex primitive \string one can turn the following ...
5
votes
1answer
132 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 ...
4
votes
2answers
123 views

Convert token to string in LaTeX3

While trying to answer another question on this site, I was experimenting with \peek_after:Nw and \l_peek_token. I can set \l_peek_token OK, but then I want to test if this token is one of several ...
2
votes
1answer
65 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 ...
2
votes
0answers
47 views

Replacing a character with other character in all the document, on specific conditions

In Hebrew, there is a special punctuation mark, called Gershayim, that's used to indicate an acronym. It's written before the last character. It looks very similar to quotation mark, and since it ...
0
votes
1answer
54 views

Gibberish string prepended to deleted text in the PDF obtained by compiling 'diff' file generated by latexdiff

I am using latexdiff for marking up corrections requested by the examiners to my PhD thesis. I have a strange issue with this. Upon compiling the diff.tex file, I get a specific string 4.0pt=-.55ex ...
0
votes
1answer
47 views

Attributing authors using shortcuts (but not with bib items)

Thanks for a great community and site! A lot of knowledge here and I am reaching out to with the hope that you can suggest a solution or point me in the right direction. I have tried to search for ...
12
votes
2answers
3k views

Alphabetic comparison of two strings

I tried to compare two strings (alphabetically), but I found some problems using the \pdfstrcmp command: 1- because it needs pdftex; 2- because it is case sensitive. The first problem is not so ...
6
votes
2answers
150 views

Pulling numbers out of a file name

A long time ago, I wanted to solve the problem where I would typeset my homework assignments, but copy the file "hw1.tex" to make "hw2.tex", and forget to change the title "Homework 1" at the top of ...
1
vote
1answer
41 views

Iterating over characters of a string during a for each loop in a Tikz picture

I am trying to make a command that renders a Tikz picture in which there is a square surrounded by a number of smaller squares on the boundary. The first parameter defines the size of the picture, the ...
0
votes
1answer
86 views

Split string variable by spaces

I am updating a custom latex class but I am a newbie with Latex and I need to parse a command like that \author{First Middle Last} into a new one \author{Last}{First Middle}. I cannot provide the \...
0
votes
1answer
94 views

separate the string by space [closed]

how to split parameter in an argument list of function by space \def\onto[1]{ ....i don't know how to do } or \newcommand{\onto}[1]{ #1 } in #1 i get hello home as 1 string in example i give \...
3
votes
1answer
106 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 ...
7
votes
2answers
179 views

How to define a comma separated list of arguments for includegraphics

I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the \includegraphics macro from the graphicx package. I would like to define the ...
4
votes
3answers
128 views

Trying to get \zap@space and \lowercase to work on string comparison

I am trying to do a non-case-sensitive check on two strings that may or may not have spaces in them. I have googled this and there is quite a lot of literature on either of these problems, but I can't ...
2
votes
1answer
286 views

Convert string to number

How can I convert numbers given as strings to "real" numbers? Consider the following MWE: \documentclass{article} \usepackage{datenumber} \usepackage{xstring} \begin{document} \newcommand{\tag}{\...
8
votes
2answers
508 views

Convert numbers to words, e.g., 111 = one hundred eleven, using the “Indian numbering system”

May I know if there is method for typesetting numbers to words using LaTeX. I have created an invoice in which I would like to convert the invoice amount to words. E.g., "1,23,456.00" should be ...
3
votes
2answers
68 views

Find the longest word in a string

Is there a simple way to get the longest word in a string? I would know how to program it in some other languages, but I'm afraid my latex kung-fu is not up to par... To make it clear, I want to make ...
3
votes
2answers
58 views

Formatting the text entered with commands in custom environment

I want to create some kind of a to-do list. Here is a simple example: \documentclass{article} \newenvironment{myEnv}[1]{% \begin{center}% --- #1 ---% \end{center} }{} \newcommand*{\...
21
votes
2answers
8k views

Replacing a substring

I've got a string like this: aXYbXYc, and need to replace the XY substring with a right arrow: a $\to$ b $\to$ c. Is there any function (also provided by external packages) to help me do that?
1
vote
2answers
53 views

How did you mention a string(chain) properly [closed]

I am writing my thesis, in my document I have several paragraphs that mention character chains, How did you mention a string(chain) properly?, for example: Si termina con $G$ no puede Si termina con '...
2
votes
1answer
91 views

Latex3: Unicode (utf8) string, weird output with pdflatex

I want to store text that contains non-ascii characters in latex3 string variables. With xelatex and lualatex it works well but With pdflatex next mwe produces incorrect output. For legacy reasons ...
1
vote
1answer
287 views

Issue with “string type” format column in pgfplottable

Using pgfplotstable library to define a table from a data file containing numeric and alphanumeric values, I get this error "! Package PGF Math Error: Could not parse input 'B' as a floating point ...
0
votes
1answer
119 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{\...