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

\string\noindent outputs a quotation mark " instead of a backslash \

I used \string\noindent to output a command \noindent, but the result is "noindent. I also tried with \verb|\noindent| and \texttt{\noindent}, but the results are the same. I found a question may ...
user avatar
  • 1
1 vote
2 answers
57 views

How to get nth occurrence in a string?

I get a string from an external program, and I would like to get each part of that string: \documentclass{article} \usepackage{bashful} \begin{document} % Test.sh would do echo "4 8 15 16 23 42&...
user avatar
  • 1,087
2 votes
3 answers
125 views

Text/string variable

Is it possible to make a command or variable to store text and then later input it in the document? Example \text1{This is text from the text1 variable and it is added in here.} \text2{This is some ...
user avatar
1 vote
2 answers
37 views

listings does not ignore comment character inside a string

I'm trying to insert a matlab code file in my tex document using listings but the output is messy because I'm using % inside a string with fprintf which is also a comment character. In the line ...
user avatar
  • 21
0 votes
1 answer
52 views

If else command

Why is the below code not working? I tried also renewcommand instead of def. The counter/\setcounter does not provide the value of the width which is why I stopped using it. Any idea of how to fix ...
user avatar
2 votes
1 answer
204 views

Why is LaTeX3 method not working with token list argument, contrary to documentation?

I have the following code in which I try to check whether a letter exists in a string: \documentclass{article} \ExplSyntaxOn \begin{document} \str_gset:Nn \ABCstring {ABC} % Setting the test string ...
user avatar
0 votes
0 answers
30 views

Repeating a string in xparse

Is it possible to repeat a string using xparse? I have the following snippet \usepackage[ISO]{diffcoeff} \usepackage{amsmath} \usepackage{amssymb} \newcommand{\lagrange}{\mathcal{L}} \usepackage{...
user avatar
0 votes
1 answer
46 views

How to replace the \\ in a given string with empty?

How to replace the "\\" in a given string with empty?, such as for any given string "how \\ are \\ you" in a latex code, we want to get how are you, how to achiever this?
user avatar
2 votes
2 answers
124 views

L3 programming: \text_titlecase only seems to map properly when sequence is explicitly declared

I'm trying to perform the following conversion using the l3 interface: my_figure_title -> My Figure Title After some trial and error with sequences and strings, here's what I came up with: \...
user avatar
  • 1,382
2 votes
2 answers
93 views

Can't output the value of uppercased string with expl3

I'm trying to get to grips with how to do basic string manipulation using expl3. Here's what I have so far: \documentclass{article} \begin{document} \ExplSyntaxOn \str_set_eq:NN \l_tmpa_str \...
user avatar
  • 1,382
2 votes
0 answers
58 views

Can you map arbitrary token sequences expandably and unambiguously to numbers or to strings of explicit character tokens of category 12?

How to map arbitrary brace-balanced sequences of non-outer tokens expandably and unambiguously to numbers or to strings consisting exclusively of explicit character tokens of category 12, if possible ...
user avatar
  • 23.4k
0 votes
3 answers
110 views

How \string and \newcommand work?

I try to write a command that each notation can link to the first appearance. Consider a notations A and a vector B. Define a command that fun{'}=B' and fun{x}=B^{x} for x=/='. If I want to write B^(A)...
user avatar
0 votes
1 answer
52 views

R - Escaping a character from the BEST package for tikzDevice

I try to modify some plot output from the R BEST package with the help of the package tikzDevice. However, apparently tikzDevice can not proceed due to a parameter with a percent sign ("% HDI&...
user avatar
  • 141
2 votes
0 answers
37 views

How to Fill a "Text" Node with Random Part of an Image?

Is there a way to fill the text of a Tikz node with one random parts of an image? It would also be nice if each part of the image can also be randomly rotated before to fill the text node. I don't ...
user avatar
6 votes
2 answers
213 views

How to Extract the Three First Letters of Current Month in French without Accented Characters?

Is there a way to extract the 3 first letters of the current month in French but WITHOUT acented characters AND with the first letter capitalized - e.g. Fev for Février (February in english) - AND ...
user avatar
2 votes
1 answer
121 views

LuaLaTeX: String substitution only in text (not in code and commands)

You can perform a string substitution with Lua code using gsub (see this answer). With \AtBeginDocument you can limit the scope of the function to the document. But is it also possible to have the ...
user avatar
  • 370
12 votes
5 answers
943 views

How can I create a comma-separated list of characters from a text string?

How can I split the string Hello World! - stored into a macro \def\mystring{Hello Word!} - into a comma-separated list of characters (including spaces) which can be used as argument of a \foreach loop ...
user avatar
0 votes
1 answer
43 views

Search for a word inside a macro using expl3

The title of this question refers to words in a general sense but in my particular case I'm searching for numbers inside a previously defined macro. In that macro I have only numbers separated by ...
user avatar
0 votes
1 answer
63 views

ConTeXt: Limit number of words

Background Every chapter title contains multiple words, but only the first two words are to be used elsewhere (e.g., page header). Problem I'm looking for a general word splitting solution that can ...
user avatar
  • 10.9k
2 votes
1 answer
41 views

Input dynamically generated file name

The situation is a bit weird and actually an excerpt from a large task. I want to remove the last two characters from the file name (\jobname) and input another file with a name with these-two-...
user avatar
  • 16.8k
0 votes
1 answer
33 views

Linebreak spacing for saved string

I have a string called \subtitle, and that string comes up at multiple locations. This string contains a linebreak, so that it shows up better at the front page. I define this string in main.tex \...
user avatar
1 vote
1 answer
38 views

Command to change a string on the whole document [duplicate]

I was wondering if it was possible to use a variable within the document to quickly change a string. For example in my cover letter I want to insert the name of a different company but without ...
user avatar
0 votes
1 answer
47 views

Sorting strings containing Cyrillic and Latin characters at the same time

I have a problem with automatic sorting of lines containing information about authors of several articles, including Russian surname, first name and patronymic, other info, ORCID and e-mail. This ...
user avatar
3 votes
3 answers
135 views

Expandable macro that extracts the first character of UTF-8/cyrillic string without additional packages

I would like to have an expandable macro that extracts the first (and sometimes the second) character of UTF-8/Cyrillic text strings without using additional packages. No simple solutions from TeX or ...
user avatar
3 votes
1 answer
41 views

Convert string of rational number to a variable and back [duplicate]

How can I convert LaTeX variables and strings when dealing with rational numbers? I have found many working examples for integers, but none for rational numbers. \documentclass[12pt]{article} \begin{...
user avatar
2 votes
3 answers
129 views

Get \string-ification of first opening brace in argument?/Get \string-ification of first opening brace's matching closing brace in argument?

Can you write a LaTeX macro where the output is the result of applying \string to the argument's first character token with category code 1 which is not a control-sequence-token and not an active ...
user avatar
5 votes
1 answer
91 views

Cases of different tokens having same meaning and same \string-representation that can occur in the stage of expansion

Please take this question for a moot point: I'd like to know about edge cases where different tokens which TeX might encounter during expansion without delivering error-messages have the same meaning ...
user avatar
  • 23.4k
1 vote
0 answers
57 views

String equality check [closed]

I want to compare 2 strings and perform different tasks based on their results(using if-else loop) My code is here: \tab• \hyperlink{new}{New Features, Enhancements, and Changes}\linebreak \begin{...
user avatar
  • 23
5 votes
2 answers
441 views

Is there a way to use string manipulations to make macro names?

Bottom line up front: what is a convenient way to input a particular character string into a \newcommand call so it can be manipulated to create multiple macro names? In particular, input (say) ABC ...
user avatar
0 votes
1 answer
95 views

Finding minimum and maximum values of arguments in function

I am defining a \newcommand called \eventsperiodslist which call some other commands: \event[]{Digits}{} and \period[]{Digits}{Digits}{} The arguments called "Digits" in \event and \period ...
user avatar
  • 454
10 votes
5 answers
542 views

Test if an argument starts with a particular string

Is there a way in tex to test if an argument starts with some string or not? And then extract the text that follows that start? As an example, I want to define a command that makes a text bold if it ...
user avatar
  • 1,531
1 vote
1 answer
40 views

Build a command for article contracté in European languages

I would like to build a command \contraction{<prep>}{<art>} to do the "article contracté" in European languages. For example, I would like to have \contraction{de}{le} return du ...
user avatar
  • 6,080
0 votes
1 answer
52 views

Splitting comma separed by comma

I'm using two indexes to build a bilingual glossary. Some words have two or more equivalent in the target language, so I should separate those equivalent in the target index. For example: the word -...
user avatar
3 votes
1 answer
35 views

Detection if image path contains string fails

For a project I would like to check if my included image is located in the sub-folder graphs or not. To check that I wrote a small MWE: \documentclass[% reprint, amsfonts, floatfix, amsmath,amssymb, ...
user avatar
  • 1,669
1 vote
1 answer
88 views

TeX \ifx conditional not working for string comparison

I would like a LaTeX source file to compile in different ways depending on the job name. However, when I run pdflatex mwe with mwe.tex containing \documentclass{article} \begin{document} \ifx{mwe}\...
user avatar
  • 69
13 votes
3 answers
357 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
3 votes
1 answer
97 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
  • 131
6 votes
3 answers
277 views

Split string into part by char position

Explanations I format a moroccan RIB (Relevé d’identité bancaire for “Bank account number”) to display it as a nice rendering. I need to take each part of the RIB to embrace it with a specific label. ...
user avatar
  • 2,080
2 votes
2 answers
110 views

Find if a string exists within external files

I'm trying to look for a way to determine if a particular text or string is present in external .tex files. It is like accepting a text input from a user and determining if that text can be found in ...
user avatar
7 votes
3 answers
1k views

Base64 encoding in LaTeX?

How can we encode some text/string using Base64 encoding in LaTeX? or any alternative solution? For example, the Base64 encoding of string Latex is bGF0ZXg=. Here's a representation of what I want to ...
user avatar
  • 147
1 vote
3 answers
100 views

LaTeX3 - Test string equality + Star version

I'm looking for some good advice on switching from (La)TeX to LaTeX3 Here is the first questions corresponding to the toy code below. What is a good way to manage an optional argument with LaTeX3? ...
user avatar
  • 11.5k
0 votes
1 answer
40 views

File name comparison with underscore

We have tested \filename{XYZ-2100011} and \include{XYZ-2100011} both input tex file name matched or not, otherwise we passed error messages in the macros. In my cases how to support input file name ...
user avatar
  • 809
1 vote
1 answer
27 views

File name string comparison

Need to show compilation error if "\filename{XYZ-2100011}" and "\include{XYZ-2100011}" input filename mismatch. For example, if \filename{ABC-2100012} and \include{XYZ-2100011} ...
user avatar
  • 809
1 vote
1 answer
71 views

How can I get a single character from a string?

I'm trying to make a command (macro? not sure about terminology) that takes in as input a string s, a number n, and a character c, and returns true if the nth character of s is c, and false otherwise (...
user avatar
0 votes
2 answers
152 views

How to multiple underline characters in strings

I need to show examples of border, cover and other regularities on a string and I would like to show that by underlining the characters of a string accordingly. Also I would like to have a larger font ...
user avatar
  • 3
3 votes
1 answer
82 views

How to use a string argument to create a macro name and invoke the resulting macro name?

I get part of a macro name as an argument. I want to use that to form a complete macro name and invoke it. How can I do that? Here is a test case to demonstrate what I am trying to achieve: \...
user avatar
  • 2,907
0 votes
2 answers
253 views

"\includegraphics{}" but for .pgf files?

I'm trying to implement a command that makes it easier to put .pgf files in my document (plots from matplotlib), similar to how \includegraphics[scale=...]{...} works for image files. However, because ...
user avatar
2 votes
2 answers
123 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
2 votes
1 answer
195 views

How to use macro with Journal Abbreviations?

I have downloaded these macros from this page. How to use it? I copy the macros to my file macros.tex. Also, I tried to save to a separate file and use \include{}. In both cases, I obtained an error ...
user avatar
0 votes
0 answers
248 views

BibTeX -- runaway string warnings?

I get these runaway string warnings which don't seem to stop my LaTeX from compiling but are annoying. How the heck am I supposed to locate a "possible" runaway string which starts at line ...
user avatar

1
2 3 4 5
9