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).

[tag?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 one also uses the primitive or dedicated packages, such as or 's string module (l3str).

497 questions
17
votes
2 answers

Replacing characters in argument strings

I am trying to create a LaTeX command that will allow me to insert pre-defined tables with a minimum of fuss. This will also allow me to change the overall format of tables (e.g. caption above or below) globally, without having to modify each…
Aikon
15
votes
2 answers

LaTeX: collecting "values" and spitting them out several times?

I'm cleaning up some old LaTeX documents describing an API. In the process I'm creating my own little style for describing the API, but I've bumped up against a bit that seems to force me into a violation of DRY. To follow the style of the old…
Magnus
  • 251
11
votes
3 answers

Evaluating a string to a command

How do I construct a string in LaTeX (perhaps with variables) that calls the LaTeX macro with the corresponding name? For example, say I have defined a comment as \def\Comment1{Example text.} and \def\CommentText[#1]{\comment#1} and I want…
10
votes
5 answers

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 length? I tried to modify the code in Split a…
mf67
  • 666
9
votes
4 answers

Tokenizing and parsing a word

After a 10+ year LaTeX hiatus I am returning and slowly getting hold again of macro writing. I now want to parse a string like "fisis" into the first letter "f" and the second half "isis". Case sensitivity is not really an issue. Valid tokens obey…
9
votes
3 answers

Split a character string n by n

I want to split a character string n by n. I know how to do that 1 by 1 : \documentclass{article} \makeatletter \def\s@plit<#1#2>{% \ifx\empty#2% #1% \else #1,\s@plit<#2>% …
Tarass
  • 16,912
8
votes
3 answers

What's the best way to explode a string into characters, process each character individually, and join them back?

I want to split a string into individual characters, transform each character individually, then join them back together. Something like…
spraff
  • 1,501
8
votes
5 answers

LaTeX count number of occurrences of a character in a string

Let's say I have some string This~is a ~test. I need to count the number of ~ characters. Is there some way to do this in LaTeX?
6
votes
5 answers

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\ConvertID#1{% \StrMid{#1}{1}{10},…
mf67
  • 666
6
votes
3 answers

Macro that reacts to the last symbol of the argument

I would like to define a macro \mynode (to be used inside TikZ) whose behavior depends on the last symbol of its argument as follows: \mynode{text!} should produce \node[fill=red] at (0,0) {text}; while \mynode{text} should produce just \node at…
Māris Ozols
  • 1,095
6
votes
2 answers

Use \item as a string in comparison

I wish to design a convenience command \lazycmd that works like this (simplified version): \newcommand{\lazycmd}[1]{% ... } % Use case 1. \lazycmd{ \item one \item two } % Use case 2. \lazycmd{ custom } \lazycmd is expected to: Add…
wdscxsj
  • 628
6
votes
1 answer

Compare strings

I have some troubles by comparing strings in my beamer theme. I would like to compare the "techno" argument with a string (iOS, Android, Java,...): if techno =="iOS" logo_path = "some_image" else if techno == "android" logo_path =…
YaGeek
  • 163
5
votes
4 answers

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
  • 1,386
5
votes
2 answers

How to get string length from multi-byte character string when passed as a \def using pdftex

I need to determine the number of printed characters from a multi-byte string. Further, the strings are passed to the routine via \def (ultimately via the readarray process to input a csv file). I am using the code from Multibyte StrLen? (StrLen for…
user150182
  • 85
  • 6
5
votes
3 answers

How can I embed xstring commands (with commands as tokens) within other xstring commands?

I'd like to manipulate strings. The following hello_en.txt should become hello. This is related to, and quite possibly a duplicate of, Command doing the same job as StrBefore but being expandable. The problem there did not really solve mine,…
1
2 3