Skip to main content
The 2024 Developer Survey results are live! See the results

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

Test a string variable if it fit's into a predefined pattern

I need to test string variables to fit into a predefined pattern. In my case, there are two different pattern which I need to test. KNX Physical Address KNX addresses are valid in this format XX.XX....
PascalS's user avatar
  • 652
0 votes
0 answers
39 views

Splitting and forwarding to bool_lazy_any in LaTeX3?

I currently have a function which does the following: \NewDocumentCommand{\myfunction}{m m m}{ \str_if_eq:eeTF{\c_sys_engine_str}{#1}{#2}{#3} } which allows me to do something as: \myfunction{...
Vincent's user avatar
  • 5,327
1 vote
1 answer
44 views

Conditionally omit protocol from hyperlink texts based on URL (Cambridge University Press style)

The Cambridge University Press style guide mandates the following formatting for URLs: ’http://’ and ‘https://’ should not be included before ‘www.’. However, if a URL does not include ‘www.’ then ...
Psychonaut's user avatar
  • 3,184
2 votes
1 answer
39 views

Link produced by href taking a command as first argument is not working "as I want"

I am trying to define a command that takes a bib key, gets its title, author, and DOI, and makes a hyperlink in which the link is the DOI address and the text shown is the paper title. I need this to ...
mikiman's user avatar
  • 23
1 vote
1 answer
103 views

Test whether a string is in a list

\documentclass{article} \usepackage{expl3,xparse} \usepackage{currfile} \ExplSyntaxOn \NewDocumentCommand \IfStringInList {mmmm} { \clist_if_in:nnTF {#2} {#1} {#3} {#4} } \ExplSyntaxOff \begin{...
mario1000's user avatar
  • 336
2 votes
2 answers
49 views

Convert list to table, number of rows

A small program that recalculates the number of records in the source list (array) and converts the list of data into a table. It works if the number of rows in the table is \def\nRows{3} is ...
Juli's user avatar
  • 121
2 votes
1 answer
97 views

Comparing strings using LaTeX3

Yesterday I asked a question about the "currfile" package I wanted to use for writing a document about several pupils in my school and @cabuha provided a very nice answer for this problem: ...
mario1000's user avatar
  • 336
4 votes
1 answer
84 views

Problems when extracting chars from data imported from csv file

In a previous post I want to compare the last character of a string with other characters I asked how to compare the last character of a string with another char, and the solutions offered have solved ...
User's user avatar
  • 61
2 votes
2 answers
222 views

I want to compare the last character of a string with other characters

I want to compare the last character of a string with other characters. If I type \ifthenelse{\equal{f}{f}}{OK}{NOT OK} it returns OK. HOWEVER, if I type \substr{asdf}{-1}{1} it returns f, BUT \...
User's user avatar
  • 61
2 votes
0 answers
87 views

Latex text reversing with Babel package

I am using the babel package, which causes text-reversal when combined with amsmath. The exact list of packages I use is: \usepackage[utf8x]{inputenc} \usepackage[hebrew,english]{babel} % Workaround ...
TheEmeritus's user avatar
1 vote
1 answer
56 views

Print \twocolumn and \onecolumn [duplicate]

How can I print \twocolumn and \onecolumn because \\ makes a new line. \documentclass[a4paper,12pt]{article} \ExplSyntaxOn \NewDocumentCommand {\lumnar} {} { \\twocolumn~and~\\onecolumn~always~...
Franklin's user avatar
3 votes
2 answers
74 views

how to transfer from a text variable a small piece of text

with the following code, I set a variable \AcIII with the bla bla text. I would extract a part of variable (i.e. the first two bla bla) and store it on another variable (that I use next). Can I obtain ...
RenatoP's user avatar
  • 851
0 votes
3 answers
60 views

In Latex3, how to test if all tokens in the input verify a test (for example \token_if_letter or \token_if_space)?

In Latex3, I would like to write a function that checks if every token of an input verify a predicate. Basically I would like the multitoken version of this command: \NewDocumentCommand{\mychecksingle}...
Vincent's user avatar
  • 5,327
2 votes
3 answers
187 views

Find Text Between tabs [closed]

I copied a sheet from google sheet into a *.txt and want to format it to a pdf. I could separate it with \loop\unless\ifeof\mytextfile \read\mytextfile to\mytextline So I have in every loop one of ...
CHP's user avatar
  • 23
4 votes
3 answers
184 views

How to substitute placeholders in string with arguments?

I'm writing a document in two languages using the macro \enzh defined as below: \documentclass{article} \newif\ifen \entrue % comment out to switch to Chinese \newcommand{\enzh}[2]{\ifen#1\else#2\fi} ...
George Tian's user avatar
1 vote
2 answers
42 views

Splitting string and retrieving part of it

I would like to take a string in Beamer and retrieve part of it. The solution at How do I split a string? gets me very close to what I want; but using it as example, i.e. if the string is: \def\...
Rigel F. do C.'s user avatar
2 votes
1 answer
81 views

Why it appears that seqsplit fails to break some strings?

I know it is possible to break long lines using the seqsplit package. The following code block shows a minimal working example. \documentclass{article} \usepackage[a4paper, showframe]{geometry} \...
Rodrigo Morales's user avatar
6 votes
1 answer
275 views

How to get the first three letters of today’s day of week?

I tried using the package datetime2 to get the whole name of today’s day of week and then xstring to trim it as desired. But when I run the following code, the result is not trimmed at all: \...
Myvh's user avatar
  • 63
4 votes
7 answers
434 views

Get string from within curly brackets

I have a function that takes a parameters with other commands. Then I split the parameter by a second command that is in the parameter. Now I need to get the parameter that is given to this command. ...
JoniBue1's user avatar
  • 103
2 votes
3 answers
181 views

Can't compare clist item with string

I can't compare comma list item with string. \clist_a is a temp var. \documentclass[12pt]{article} \usepackage{expl3} \begin{document} \ExplSyntaxOn \clist_new:N \clist_a \keys_define:nn { mymodule } ...
zpding's user avatar
  • 134
4 votes
1 answer
89 views

How to add a space after a \string command otput in .log file

Consider this code, adapted from the command \incompatible@package of RevTex4-2. The relevant part is just the \string\usepackage\ statement in the line beginning with \def\@tempa: \documentclass[12pt]...
linguisticturn's user avatar
5 votes
2 answers
316 views

Delete non-ascii characters from string? No special chars involved. Do not need to replace them

After browsing, I see that this kind of question has been answered for other programming languages (R, Python, etc.) but not for TeX (specifically lualatex) The only related questions on this topic ...
user avatar
0 votes
1 answer
75 views

Loop Through Array of Strings (Actually an Array of Array of Strings, e.g. `{{black, ab}, {white, cd}}`)

I'm drawing stones on a Go (game) board with SGF coordinates (which I only managed to do from the the help people gave me on this question) like this \drawStoneFromSgfCoords{ab}. However, there might ...
psygo's user avatar
  • 438
0 votes
1 answer
63 views

Converting String Coordinates to Number Coordinates (e.g. ab -> 1 and 2)

I'm trying to draw stones on a grid, and my macro API will have two ways of doing it: either you give the X and Y coordinates, or you give it a string of the coordinates. So, for example, ab should be ...
psygo's user avatar
  • 438
5 votes
3 answers
236 views

Counting the number of occurences of specific characters in a string in an expandable way

This question shows how to count the number of occurrences of a specific character in a string. I would like to do it in an expandable way, and for a list (not only one) of specific characters. \...
Vincent's user avatar
  • 5,327
4 votes
3 answers
148 views

Problem with a command that prefixes words only if needed when the arguments are provided through macros

Consider the following code coming from this answer, where it adds a prefix to a word, only if the prefix is missing. \documentclass[border=6pt,varwidth]{standalone} \ExplSyntaxOn \...
Vincent's user avatar
  • 5,327
6 votes
5 answers
479 views

Reformat a string and remove leading zeros from substrings

I have strings such as 2011-10-29--2-03 but I want to display them as 2011-10-29, p. 2, fig. 3 I tried \documentclass{article} \usepackage[T1]{fontenc} \usepackage{xstring} \begin{document} \def\...
mf67's user avatar
  • 668
10 votes
5 answers
515 views

Split string in characters and merge with formatting

How can I create a macro \split{ABC} that outputs where the formatting of the characters are made with another macro, i.e. \formatchar{A} where \def\formatchar#1{{\color{red}#1}} for any string ...
mf67's user avatar
  • 668
1 vote
0 answers
157 views

LaTeX: How can I escape arbitrary text as a literal string? [closed]

I have a build system for my latex files that injects some environment variables into the latex file that is to be compiled. Usually, the environment variables contain path to image files. So, a build ...
HappyFace's user avatar
  • 153
4 votes
2 answers
105 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
4 votes
5 answers
416 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,201
0 votes
1 answer
59 views

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

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
  • 153
0 votes
0 answers
57 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
  • 279
3 votes
1 answer
115 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-...
zpding's user avatar
  • 134
1 vote
1 answer
116 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
  • 2,115
5 votes
4 answers
606 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,428
2 votes
1 answer
317 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
81 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
  • 5,327
3 votes
3 answers
466 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
  • 9,004
2 votes
1 answer
114 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
1 vote
1 answer
127 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,333
2 votes
0 answers
36 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
111 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
129 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
261 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,597
3 votes
3 answers
143 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
  • 515
0 votes
0 answers
45 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
  • 337
1 vote
0 answers
62 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
23 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,970
0 votes
0 answers
129 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
  • 473

1
2 3 4 5
11