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
1answer
69 views

latex(VAR) command converts other concatenated strings into mathemode when latex displays it

Using sagetex in latex; it appears that using the latex() command converts any concatenated strings to that term into math-mode, rather than strings. See the MWE below: \documentclass{article} \...
2
votes
1answer
32 views

Invoking functions indirectly (using a string) in BibTeX

Is it possible to do indirect function calls in BibTeX styles, i.e. to get the function name from a field in the .bib? EXECUTE would be able to do that but these statements don't work within functions(...
5
votes
3answers
216 views

Methods for replacing character-tokens of catcode 12 in strings by other tokens?

Assume you have a non delimited macro argument which forms a string/a sequence of arbitrary length of character tokens of category code 12. And all instances of some characters in that string shall ...
1
vote
2answers
49 views

Biblatex : What is the name of the string containing “[online]”?

I am writing a document in French using Biblatex with the iso-numeric style. I need to translate [online] into French, but I didn't find the corresponding string in the documentation. Does anyone know ...
2
votes
2answers
54 views

Macro changing a string depending on letter case

I would like to define a new mathmode command such that: the input is a string s; the output is the same string where the font of each caracter has been changed depending on whether the character is ...
0
votes
2answers
43 views

Change order of substrings

I have a string such as 123p456789m333s22z (that denotes a Riichi mahjong hand). I need to invert the order of every letter-number pair within that string, so I get a string like p123m456789s333z22. ...
10
votes
1answer
751 views

Color coding in Python f-strings

Since Python 3.6, released Dec 2016, there is new f-string formatting, where, inside your string you can put python code to be evaluated in {}s. It's fantastic but TeX packages for code listings with ...
3
votes
4answers
180 views

Prevent hash doubling with \message

Assume a token sequence: Token 1: Explicit hash character of category code 6. Token 2: Explicit 1 of category code 12. Token 3: Explicit hash character of category code 6. Token 4: Control word token ...
0
votes
2answers
37 views

User-defined command that inserts random words

Is there a way to write a user-defined Latex command that takes no arguments and returns the nth string from a repository of strings? baseball,marble,coin,watermelon,beachball Johnny threw a \myWord{...
0
votes
2answers
83 views

How to quickly switch .tex-file by passing arguments to filename?

For example I have two TeX Projects with a similar filename structure: The master.tex has a structure like this: \input{preamble.tex} % <- \bibliography{Projekt_A_Literature} in preamble % ... ...
5
votes
2answers
133 views

Why does nesting some xstring commands causes errors?

Why does combining some command of the xstring package causes errors? e.g. when I compile the following MWE: \documentclass{article} \usepackage{xstring} \begin{document} \section{A} \StrCompare{\...
0
votes
1answer
46 views

\tikzsetnextfilename externalize with filename as variable

I want to externalize my pictures with the external tikzlibrary. The problem is that there are pictures created inside \newcommand and i have to automatically set the filename tor the externalization. ...
2
votes
1answer
33 views

Text manipulation with xstring failing: \@xs@StrRemoveBraces@@

Consider the following document: \documentclass{article} \usepackage{xstring} \makeatletter \newcommand{\mycommand@firstchar}[1]{% \StrRemoveBraces{#1}[\FirstChar]% \StrChar{\FirstChar}{1}[\...
0
votes
1answer
49 views

Switch condition (IfStrEqCase) - no match & use inside pgfplot axis

I am trying to learn how to use switch conditions to apply in a document I am creating that contains plots. Here is an extract to create a MWE : \documentclass[border=2pt]{standalone} \usepackage[...
3
votes
1answer
28 views

User defined command inside a section title. xstring and bookmark (hyperref) involved

I'm trying to define a command to "centralize" the titles of some sections (that are used in more places inside the document). So I thought that creating a command with a number as argument (the ...
3
votes
1answer
51 views

Files not found because of \endlinechar (space) character

A recent MikTeX update broke some code that I'm using. I have many files filled with filenames, the code reads these filenames, and then does some stuff with the contents of the corresponding file. ...
1
vote
1answer
38 views

Count Number of Occurrences as Numerical Input for Other Macro

I am trying to make lingmacros gloss automatically be aware of the number of columns it will need to produce. Basically, for the \shortex command, one of the inputs is the number of columns you want ...
3
votes
4answers
85 views

How do I pad a string argument to a macro to a set length string

So I have a string being passed as an argument to a macro. This string could contain up to 10 characters, but I need latex to 'pad' the string out so it ALWAYS contains 10 characters (by putting ...
1
vote
4answers
96 views

Definition of starred commands with `csname`

I want to define a command, let's call it \commander, for defining starred and non-starred versions of a new command. \commander would be called as follows: \commander[<options>]{\thenewcommand}...
2
votes
1answer
72 views

Expandable case insensitive switch case for string comparison

I have spent the last few hours trying to come up with a good solution for my problem, but alas all solutions falls short. I want to create a switchcase for a function (In reality I need many ...
0
votes
1answer
78 views

Is there a command, macro or tool that can get the string result (as in other languages) of any macro in an easy to use way? [closed]

I don't want to go down into the depths of expandable and not expandable. I doubt that I will be able to understand my self-developed designs a few weeks later. Therefore I am looking for a universal ...
4
votes
1answer
50 views

What tools/libraries are available for displaying string algorithms?

I would like to write up a string algorithm similar to the image shown below, but I'm not sure which tools would be best for this. I could use tabular for boxes or tikz to generate nodes on a grid-...
1
vote
1answer
141 views

Comparing strings; genitiv version of \cref command

I am working with cleveref in a German document and i need in some cases the genitive of the word given by \cref{}. The problem is, that the German genitive is not equally build for all words, so i ...
2
votes
1answer
39 views

Turn string into macro (change catcodes)

Is it impossible to covert string back into macro? I know that with lualatex we can do a lot of funny things with macros. I have never seen string converting without it. \documentclass{article} ...
0
votes
1answer
223 views

Ignore the part [^\\] in Lua pattern

I want to find char $ using lua features, but only if there is no \ char before char $. For this I create the pattern: ([^\\]?)%$ However, Lua ignores the first part of my pattern and finds only %$....
1
vote
1answer
93 views

variable font formatting

I would like to create a LaTeX function that: (1) takes a string as an argument (2) calculates the length of the string, (3) divides the length by 3, (3) applies one type of formatting to the first 1/...
0
votes
0answers
59 views

How to read a picture with name # in it?

Probably avoiding to use # would be best at the first place but for musical chords I would like to name my image something like F#m.png . The problem is that latex does not allow to write \...
1
vote
1answer
53 views

if/else to test if a string is empty failing

Using the following \def \ifempty#1{\def\temp{#1} \ifx\temp\empty } \def \mymacro#1{ \ifempty{#1} empty \else not empty \fi } \mymacro{something} % prints "not empty" \mymacro{} % prints "...
6
votes
2answers
341 views

Checking if an integer is a member of an integer list

Is there any way to check whether an integer is a member of a list of integer numbers and return a boolean? I found this neat solution, here that does a great job. It checks whether a string exists ...
1
vote
0answers
33 views

Membership checking inside fpeval [duplicate]

I would like to check whether a number is in a list and make a decision in the calculation of a macro. I found a neat solution to check the membership of a number, here and it works as long as I don't ...
0
votes
1answer
68 views

Using output of one lua function as input of another function in tex file

The following is the code. \documentclass{article} \usepackage{luacode} \begin{document} \begin{luacode*} function string(x) tex.sprint(x) end function combine(x,y) tex.sprint(x.." "..y) end \end{...
1
vote
4answers
82 views

How to split a string variable into an array and call from an array

I'm fairly new to LaTeX, and want to know if I have a string John Citizen how can I break down so that I can access John and Citizen independently of each other through out the document. Currently my ...
2
votes
3answers
74 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
126 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
36 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
38 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
40 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
34 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
286 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 ...
1
vote
1answer
32 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
63 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
53 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
208 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 ...
1
vote
1answer
27 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
2answers
90 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
316 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 ...
5
votes
2answers
101 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,...
3
votes
3answers
94 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 ...
2
votes
2answers
124 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....
0
votes
0answers
20 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 ...

1 2 3 4 5 7