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
3 votes
2 answers
79 views

ConTeXt: Escape hash symbols for use with lpeg replacer

Background Looking to perform a text substitution on arbitrary strings. In the code snippet, the value #a.m. #p.m. value comes from a document. More specifically, the input is an XML document ...
Dave Jarvis's user avatar
  • 11.6k
4 votes
5 answers
382 views

Macro to remove all non-numeric characters from its argument

In a custom class I defined a custom command to typeset a telephone number, \newcommand{\phone}[1]{\def\@phone{#1}} I use this \@phone macro inside my class when I want to replace with the value from ...
Lin's user avatar
  • 1,181
0 votes
1 answer
22 views

How do I replace a specific string with its bold version?

I want to bold my own name in the publication section of my CV. I have tried: \usepackage{xstring} \newcommand{\highlightname}[1]{ \StrSubstitute{#1}{My Name}{\textbf{My Name}} } \begin{enumerate} ...
HappyFace's user avatar
  • 143
0 votes
0 answers
49 views

Universally usable macro definitions with literal UTF-8 content

Since UTF-8 is the default input encoding, it should be straigthforward to use literal Unicode characters in macro arguments,e.g. \newcommand*{\regards}{Grüße} This fails, if the macro is defined in ...
G. Milde's user avatar
  • 159
3 votes
1 answer
84 views

Can't check if a string(token list) type macro in a sequence in LaTeX3?

This is my first time on TeX Stack Exchange, so please forgive me if I unintentionally offend anyone. Compile Environment(using pdflatex to compile): WSL: x86_64 Linux 5.15.133.1-microsoft-standard-...
zongpingding's user avatar
1 vote
1 answer
109 views

To make "\" to category 12, why should convert it to category 13 in TeX?

Exercise 7.5 on page 40 of The TeXbook asks to make \ to category 12. The answer of this question is {\catcode‘/=0 \catcode‘\\=13 /message{/string\}} Why should assign the \ to 13 not 12? The ...
Y. zeng's user avatar
  • 1,801
5 votes
4 answers
583 views

Command to insert a string between each character in another string

I would like a command \initials that takes a string and inserts another string (e.g., ~) between each character. So \initials{GRRM} would be typeset as G~R~R~M.
Fredrik P's user avatar
  • 1,386
2 votes
1 answer
280 views

Convert Date string format from dd-mm-yyyy to dd.mm.yyyy with some feature

I need to convert a date from one format to another. This is a very simple problem that has already been solved in the topic Latex convert Date string format from mm/dd/yyyyy to dd/MM/yyyy. However, ...
Crosfield's user avatar
  • 119
1 vote
3 answers
74 views

Branch over number of characters of an argument provided to a macro

I currently have the following command: \newcommand*{\setfontshape}[1]{\@ifnotmtarg{#1}{\csname#1shape\endcsname}} that helps me produce the command: \scshape from text sc. I would like to modify my ...
Vincent's user avatar
  • 4,703
3 votes
3 answers
455 views

Why are my newlines turned into \Omega?

If I use ^^J or \iow_newline:, it prints a \Omega instead of a newline. Any idea what I got wrong? \documentclass{article} \ExplSyntaxOn \NewDocumentCommand{\printTwiceWithNewline}{v}{ \...
tobiasBora's user avatar
  • 7,803
1 vote
1 answer
95 views

ConTeXt: Pass text value into text background graphic

Background Looking to draw dynamically-derived text as a "legend" for a paragraph that spans multiple pages. Version: 2023.07.18 22:07 Problem The text doesn't appear where desired. Code ...
Dave Jarvis's user avatar
  • 11.6k
1 vote
1 answer
90 views

Testing if a string is a part of a csv list of strings

I use the xsim package with tags for my exercises. These tags are a CSV lists of strings. I have a tag called year (year={2020-2021,2017-2018}, for instance) which contains school years. I can ...
Didier's user avatar
  • 1,291
2 votes
0 answers
31 views

xstring testing: help needed for testing chords typeset with leadsheets package

For a personal songbook project I use the leadsheets package. Later on, I want to automatically typeset guitar chord diagrams based on the chords of a song, even if the song is transposed via the ...
KSTNR's user avatar
  • 53
1 vote
2 answers
101 views

Expandable macro that extracts the first characters of many words for UTF-8/cyrillic or UTF-8/ASCII string without additional packages

There was a problem to slightly change the macro described in Expandable macro that extracts the first character of UTF-8/cyrillic string without additional packages for the argument which may contain ...
Crosfield's user avatar
  • 119
0 votes
1 answer
79 views

Remove extra spaces and curly braces latex code in string Python (normalize string in python)

I want to normalize string in python. For example, I have a LaTeX code str='{{{ \\dfrac{{3}}{{4}} + \\sqrt{3} }}}' I want to get the string str='{\\dfrac{3}{4}+\\sqrt{3}}' Remove extra ...
ducanh2021's user avatar
3 votes
2 answers
189 views

LaTeX3 how to use content/value of predefined command in token list/string?

First of all, I guess that will be a very easy answer for people who are experienced in expl3. But for me its new and I'm very willing to learn that stuff to understand Latex3 better. So I hope for ...
lukeflo's user avatar
  • 1,483
3 votes
3 answers
138 views

How to automatically wrap lines in scriptio continua

How to wrap lines automatically for scriptio continua (contexts in which there are no devices whereby to separate distinct words)? I am using XeLaTeX. For example, the following code does not produce ...
Noah J's user avatar
  • 483
0 votes
0 answers
42 views

Wrapping long url hyperlinks that contain no spaces within a table [duplicate]

For some reason, I have been unable to wrap an href within a table using the solutions presented here: Wrapping long lines that contain no spaces And, here: Forcing linebreaks in \url Any suggestions ...
Steven's user avatar
  • 317
1 vote
0 answers
51 views

Compare Token List result to a string

I have a command that (beyond my control) evaluate into a token list, and I want to compare it to a given string, I tried to follow this answer and create a variant on \tl_if_eq: \ExplSyntaxOn \...
Yuval Shmuel's user avatar
0 votes
1 answer
22 views

the string position in code doesn't correspond with the position in the output pdf

I have a code like below, and I want to insert the string "22222222222222222222222222" at the place above \date{today} as is in the code, but it appears on the first page and today is on the ...
user2925716's user avatar
  • 1,920
0 votes
0 answers
98 views

Is there a way to remove specific characters from argument of a macro?

Suppose we have a macro saying, \NewDocumentCommand\foo{m}{#1} When it eats an argument, I want it to print whatever is in the argument without specific characters. For instance, I want to remove ...
Gau-Syu's user avatar
  • 463
0 votes
1 answer
36 views

Argument not returned for some options

When using one option of a \str_case for the case noseperator the returned string is empty. I do not understand why... \documentclass{article} \RequirePackage{booktabs} \usepackage[mode=text, reset-...
mrCarnivore's user avatar
  • 1,475
2 votes
1 answer
94 views

Assigning commands to str does not work

I want to assign the values of other commands (like \nobreakspace) to a string to be able to use these later. Assigning does not seem to work as it is taking the commands literaly... \documentclass{...
mrCarnivore's user avatar
  • 1,475
1 vote
1 answer
38 views

Copying one string into another does not work expl3

I try to create a command that shows the euro value. I want it to show different types (0 decimal digits, 2 decimal digits or all decimal digits) and have this set by a \seteurformat command. That ...
mrCarnivore's user avatar
  • 1,475
2 votes
2 answers
120 views

How to store data from a text file into Tikz variable?

I am trying to pass values of variables I am using in my Tikz plot using the text file. I am not sure how to convert data from string to character. Here, the automaton.txt stores some array values (...
Mostafa's user avatar
  • 47
2 votes
1 answer
54 views

Getting a substring from a string which is stored inside a variable in LaTeX

I currently have the following problem for which I couldn't find a solution for. It's about getting a substring from a string variable... I've a nested list of values: \ExplSyntaxOn \...
Mahakala108's user avatar
2 votes
1 answer
129 views

How to make this sliding window?

Book: Handbook of Exact String Matching Algorithms Update: % compiler: xelatex \documentclass{report} \usepackage[top=2cm, bottom=2cm, left=2.5cm, right=2cm]{geometry} \usepackage[utf8]{inputenc} \...
hungngt's user avatar
  • 23
0 votes
2 answers
39 views

Concatenating macro parameter and string adds unwanted space [closed]

I wanted do define a simple macro like the following: \newcommand{\testcommand}[1]{ \includegraphics[]{pictures/#1.jpeg} } But this does not work because it adds a space between the argument #1 ...
Pa Dalton's user avatar
1 vote
2 answers
96 views

Creating "static" arguments in a string

Is there a trick to integrate arguments "statically" in a given string, to use this string in another command that will then process the argument ? Something like : \edef\mystring{Hello #1 !...
Jean-Louis Brabant's user avatar
3 votes
2 answers
424 views

How to typeset a regular expression string in a LaTeX table?

I want to typeset a table with regular expressions in one column of the table. The data that I want to put in the table is below: I have tried with following code: \newcolumntype{e}{>{\hsize=0.02\...
Setu Kumar Basak's user avatar
4 votes
1 answer
122 views

Header which contains list of all elements on page

I want to define a ''question" environment which interacts with the header of my latex page. The question environment will modify the header of the page which the command is found on. Ideally, ...
Michael Klyachman's user avatar
0 votes
1 answer
141 views

How to auto replace string pattern in header CSV cells with pgfplotstable?

In the following csv file example, I want to automatically replace a string pattern in all headers cells when importing with pgfplotstable: \begin{filecontents*}{sample.csv} parameter,cubic ...
zetyty's user avatar
  • 769
1 vote
1 answer
77 views

Is there any way to retrieve saved string in the beginning of document from its end in LuaLaTeX?

There are different types of “registers” in LuaTeX. With totcount package, you can save counter (number) from any place in a document and get its value also in any place in a document with the help of ...
Andrew15_5's user avatar
0 votes
0 answers
55 views

Transferring the concepts "string" and "character" into TeX/LaTeX

(Looking at packages like l3string, xstring and stringstrings tempted me to post the following: ) The concepts "string" and "character" to me seem not well defined in (La)TeX. ...
Ulrich Diez's user avatar
  • 27.5k
0 votes
0 answers
117 views

ifstrempty Renders always False

The following minimal example makes problems: \usepackage{etoolbox} \newcommand{\foo}{} \begin{document} \ifstrempty{\foo}{True}{False} % This is always False \end{document} Why is ifstrempty ...
flymg's user avatar
  • 169
2 votes
2 answers
157 views

Using \g@addto@macro in a loop

I am confused when using \g@addto@macro in a loop. My code is: \documentclass{article} \usepackage{ifthen} \usepackage{newfile} \usepackage{xstring} \makeatletter \DeclareRobustCommand\@initial[1]{#...
Crosfield's user avatar
  • 119
2 votes
2 answers
68 views

How to compare an argument to a given string, within a 'newenvironment' definition?

Problem description I am trying to create an environment that produces boxed paragraphs with different styles. So I tried to implement some "if"-"elif"-"else" blocks, ...
Mycroft_47's user avatar
1 vote
0 answers
22 views

Biblatex : replace "In" by another entry in APA style [duplicate]

I would like to put the strings like "In" in french (so "Dans") in a APA bibliography with biblatex. I tried to use the answer of this post, it works until I put the biblatex style ...
Ink's user avatar
  • 13
1 vote
2 answers
43 views

Using string to process a macro name using listofitems seems to fail

I am trying to process the name of a command using listofitems, but when I am using \string to convert that command it does not behave the way I think it would behave. Here is a code to illustrate: \...
Vincent's user avatar
  • 4,703
5 votes
3 answers
511 views

How to write a fully-expandable string slice in LaTeX3

I am trying to create a LaTeX3 function that slices a string at the first - character. So far I have \cs_new:Nn \__slice_at_char:NN { \int_set:Nn \l__slice_pos_int {1} \str_map_inline:Nn #1 { ...
Jason Siefken's user avatar
3 votes
1 answer
96 views

ConTeXt: Replace matching substring with macro output

Background Looking to replace a string within a document with an equivalent string created using a macro. For example, I'd like to replace "McAnulty" with "\Mac Anulty". Problem ...
Dave Jarvis's user avatar
  • 11.6k
3 votes
2 answers
198 views

Automatically highlighting name in bibliography doesn't work with middle initial

I've been trying to figure out a way to automatically highlight my name in the bibliography. I thought that I could just compare first name and \namepartgiven and last name with \namepartfamily, but ...
George Wei's user avatar
0 votes
1 answer
66 views

How to pass the content of a TeX variable to Lua without luastring and luacode?

I try to pass the content of a Tex variable to lua, but I don't use luacode. Is there a way to avoid it ? \documentclass{article} %\usepackage{pgfkeys} %\pgfkeys{ % JobName/.code={\directlua{ ...
Tarass's user avatar
  • 16.9k
0 votes
1 answer
72 views

How to expand a macro argument into a string, remove all the spaces, then append and prepend the string inside a \NewDocumentCommand macro definition?

I want to expand a macro argument into a string, remove all the spaces, then append and prepend the string inside a \NewDocumentCommand macro definition. Here's my MWE using LuaLaTeX. \documentclass[...
Farrel Ahmed's user avatar
1 vote
1 answer
79 views

ConTeXt: String substitution to include macro

Background A Markdown document uses certain strings that are to be typeset in a special way. In this case, we'd like to typeset a.m. and p.m. as small caps wherever that text appears in the source ...
Dave Jarvis's user avatar
  • 11.6k
2 votes
1 answer
71 views

A macro that takes in a variable that is a number, interprets it as a string, check if it has a plus sign, removes it, then stores it to the variable

I want to create a macro \foo that takes in a \newcommand variable that is a number, e.g., \bar where it's defined as \newcommand{\bar}{<number>} and interprets it as a string, then checks if ...
Farrel Ahmed's user avatar
2 votes
1 answer
144 views

Remove all spaces from string (including \quad and \hspace)

I want to retrieve all characters besides any space (tabulation) ones including , ~, \space, \enspace, \quad, \qquad etc. that have been passed as an argument. Say we have a command \removespaces{...}...
antshar's user avatar
  • 4,126
3 votes
4 answers
939 views

Convert numeric string to Roman numeral

I have a (sub)string (not a counter) which consists of an Arabic number. Is there an easy to convert this string to a Roman numeral? I suppose I could build an array of sorts, but I think this would ...
Ingmar's user avatar
  • 6,650
1 vote
1 answer
87 views

Writing to a file values of function in expl3

I'm trying to master LaTeX3 using the example of the problem of parsing LaTeX code and then writing function values ​​to a file. Problem. Generate a piece of XML file in pdfLaTeX containing normalized ...
Crosfield's user avatar
  • 119
1 vote
0 answers
69 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 ...
Qiang's user avatar
  • 11

1
2 3 4 5
10