{strings} are sequences of characters (most commonly literal constants).

learn more… | top users | synonyms (1)

29
votes
5answers
1k views

Censoring Curse Words with Grawlixes

Suppose that I would like to censor a curse word <word> using grawlixes, e.g. "What the #@$! are you doing?!" How can I define a command \censor such that \censor{<word>} results in a ...
26
votes
2answers
1k views

Introspection and reflection with LaTeX/TeX macros

Below is a short program that can use \meaning and \string to let a combination of LaTeX and TeX commands to print out the listing of macros. Unsurprisingly (nothing can surprise me with TeX any ...
22
votes
2answers
4k views

How do I split a string?

I need to split a string into one or more substrings. I know that I could use the xstring package, but I'd like to do it using only inbuilt TeX/LaTeX commands. So, if I say \def\MyTeXKnowledge{Not ...
21
votes
2answers
618 views

Change the color of capital letters

Is there a way to define a command that changes the colour of any capital letter in an input string? Most of the results I find when I type "LaTeX string capital" are results about capitalizing the ...
20
votes
4answers
1k views

How to convert a one digit number to a two digit number

I have a table that represents a timetable for bus, so each cell contains time of departure as hour followed by minute, both as two digits, but sometimes I don't have two digits,just one so I have to ...
18
votes
3answers
2k views

Extract first & last characters of macro argument?

In LaTeX, how do I extract/isolate/determine the first and last characters of a macro argument? Specifically, in the case I'm dealing with, the argument happens to be a base-10 integer (call it N). ...
15
votes
3answers
2k views

\string command behavior - Plain TeX

I would like to learn Plain TeX and I'm reading Knuth's "The TeXBook". At Chapter 7, Knuth talks about the \string command and how it converts control sequences into lists of characters tokens. Why ...
15
votes
3answers
304 views

Parsing strings containing diacritical marks (macros?)

I apologize that this question may seem very much like several other recent ones I have asked (Parsing leading hardspaces, Parsing a \$ as part of an improved \getargs command). They are all related ...
15
votes
3answers
12k views

\uppercase in \newcommand

I tried to use \uppercase in \newcommand: \newcommand\universidad{My University} \newcommand\Universidad{\uppercase{\universidad}} When I use this I get My University and not MY ...
14
votes
3answers
897 views

Equivalent to “in” operator

I want to write a command that responds to an argument being in one set of reference strings or another. The argument takes a (musical) note name, and the command will print an accidental depending ...
14
votes
2answers
335 views

String comparison in \ifthenelse

I want find a certain line of text in a data file cities.txt: A;London B;Berlin C;Paris with the xstring and [xifthen][2] packages: \documentclass[12pt, a4paper]{article} \usepackage{xstring} ...
13
votes
7answers
985 views

How to get the string with \

Apologized for my unclear description. I wish I could explain my problem more clearly. In document, I wish I can just write something as "how to use \cmd \mbox in xxx" or "what is \cmd minipage ...
13
votes
3answers
446 views

Extract the numerical and non-numerical portion from text

I would like to extract the leading number and subsequent text from a string. I have an idea of using the xstring package to gobble characters from the right until I end up with a number or an empty ...
13
votes
2answers
878 views

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 ...
12
votes
2answers
1k views

Alphabetic comparison of two strings

I tried to compare two strings (alphabetically), but I found some problems using the \pdfstrcmp command: 1- because it needs pdftex; 2- because it is case sensitive. The first problem is not so ...
11
votes
3answers
2k views

How to concatenate strings into a single command?

I'd like to concatenate several parts of math text into a single command, and i read a great solution here on this site, allowing me to create this working example of what i mean : ...
11
votes
3answers
1k views

String replacement in LaTeX

I'd like to know how to replace parts of a string in LaTeX. Specifically I'm given a measurement (like 3pt, 10mm, etc) and I'd like to remove the units of that measurement (so 3pt-->3, 10mm-->10, ...
10
votes
3answers
437 views

TeX capacity exceeded while parsing a date string

I'm trying to parse a date (say, a due date) in a DD-MMM-YYYY format, e.g., 06-May-2012 and create macros \dueday, \duemonth, and \dueyear. I use xstring's commands to extract the substrings. Then I ...
10
votes
3answers
173 views

how to select a character (or word) from a list

Is there a way, with the following restrictions: No external pacakges (i.e., no substr) no conditionals (\ifnum, \ifdefined, etc) to select a character from a string? i.e. \CharAt{2}{ABC} ...
10
votes
1answer
3k views

Replacing a substring

I've got a string like this: aXYbXYc, and need to replace the XY substring with a right arrow: a $\to$ b $\to$ c. Is there any function (also provided by external packages) to help me do that?
10
votes
1answer
259 views

How to replace a given string in a bibliography with biblatex?

Mendeley allows you to emphasise Latin names in article or report titles using HTML notation like so: A treatise on the ecology of <I>Rattus rattus</I> Using biblatex, the tags are ...
9
votes
3answers
1k views

Extract number from string and compare problem

I try to extract the year, month and day from a string and write different text depending on the given date. I thought I could use xstring and etoolbox, but I can'st get it to work. Here's the code ...
8
votes
4answers
352 views

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 ...
8
votes
2answers
1k views

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 ...
8
votes
2answers
144 views

How can I combine two text strings to represent the name of a command?

I want to combine one command with a text string to represent a second command. In MatLab it would be possible to concatenate these two strings into one string and evaluate this new string. However I ...
8
votes
1answer
198 views

How to place a # character in a message?

How can I place a # symbol inside of a \PackageWarning inside of a macro definition? I tried: \PackageWarning{package}{# or \# or \string# or \hash} but either ## or unknown (for \hash) or Illegal ...
8
votes
2answers
354 views

Words of more than 32765 characters

When I compile the following document: \documentclass[10pt, oneside, a4paper]{report} \begin{document} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \end{document} where the number of x's is greater than ...
8
votes
2answers
128 views

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>% ...
8
votes
1answer
110 views

How to do multiple string replacements?

I want to escape URL paths to obtain the percent-escaping that is also applied e.g. by browsers. For this purpose I tried to do the following (out-commented lines are meant to show what I'm aiming ...
8
votes
1answer
281 views

How do I store the upper case counterpart of a string?

I have a string stored in a variable \word, and I want to store its upper case counterpart in another variable \WORD. If I try \def\WORD{\MakeUppercase{\word}} \show\WORD then the message ...
7
votes
3answers
871 views

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 ...
7
votes
4answers
784 views

Logical String Length

How do I do a conditional 'if then else' statement, based on length of string being greater than (or less than, or equal) a specified value. For example, something Like \def\mystring{XYZ} ...
7
votes
1answer
216 views

Comparing LaTeX3 token list to string

Is there a way to compare a LaTeX3 token list to string without having to create a temporary token list? I though I'd use \tl_use:N to get the contents of the token list for the comparison, but that ...
7
votes
1answer
185 views

How to detect that some macro expands to empty string or spaces only?

I need to check several macros and do some actions only if their expansion is not empty nor space only. In pseudo code I would look like this \if\macroToBeTested \doSomething ...
7
votes
1answer
517 views

Macro to extract (typeset) 'plain text' from a command?

Sorry to come back again with a similar post title (I had a post with this same title, then renamed it to PDF Metadata - Macro to extract (typeset) 'plain text' from a command?) - but I hope now the ...
7
votes
1answer
505 views

string manipulation and catcodes

I want to detect whether an input line contains a certain substring, similar to the problem discussed here: Check if a string contains a given character The complicating problem is that the match ...
7
votes
1answer
175 views

Change the way XeTeX sees a string before running/building PDF

For some reason, I'm really struggling to articulate my question, so let me apologise in advance. I may not be approaching this from the right angle. I'm working in XeTeX (and it's far too late to ...
6
votes
2answers
532 views

Replace characters in string based on preceding and following character

The following two strings are the result of the expansion of a biblatex citation command: Unicom Computer Corp. (in re), 13 F.3d 321, 30 Collier Bankr. Cas. 2d 655, 25 Bankr. Ct. Dec. 152 (9th ...
6
votes
3answers
474 views

Conditionally including a TikZ figure

I have the following construction for a figure. The background is, when \submit is defined, only the caption is included, but no figure. Otherwise the figure is included. The problem is that I have ...
6
votes
3answers
264 views

How to remove all dashes (-) using a macro?

In a package, I'm building macro names from the values of options passed to a function. Now, the values should also allow a - inside, but the command names I'm building with \csname do not. So, I need ...
6
votes
2answers
2k views

How to concatenate strings, to e.g. create commands that return lists?

I was thinking about Felix' Question, where he wanted to return lists in TikZ. My approach so far was to return the single results as individual \nodes, separated one centimeter each. Now I would like ...
6
votes
2answers
303 views

How to use @STRING variables in the note field of a .bib file?

I defined a @STRING in my .bib file as follows: @STRING{mytext = {Last accessed: }} This is an entry in the bibliography. @ARTICLE{knuth:1974, author = {Knuth, Donald E.}, title = {{C}omputer ...
6
votes
1answer
8k views

Using string variable with LaTeX

I would like to define one variable containing some text that can be changed locally. The following code gives one example of the featuring I'm looking for. \documentclass{article} ...
6
votes
1answer
175 views

How do I implement a string buffer in TeX?

I've recently learned how to create a macro to iterate over a token sequence using \afterassignment and \let in TeX. Currently, I'm trying to apply this to a tokenization macro (where "tokenization" ...
6
votes
1answer
281 views

Why can't I compare a string with \par?

First of all: the package xstring cannot recognize a \par as argument. When I for example do this: \usepackage{xstring} \def\apar{\par} \def\str{a string} \IfStrEq{\str}{\par}{% true part }{% false ...
6
votes
1answer
672 views

How to capture the result of \StrSubstitute into a macro?

I have a macro, say defined as follows: \edef \temp{A.input 1} I want to replace the dot with hyphen and have the result being stored in \mystart. Something like that: \edef ...
6
votes
2answers
830 views

Nest StrLen and ifthenelse commands

Here is a sample of code I am working on: \documentclass[10pt]{report} \usepackage{xstring} \usepackage{ifthen} \begin{document} \StrLen{123456}\\ %Prints 6 ...
6
votes
2answers
351 views

xstring functions in section/paragraph headers

In the following example, \documentclass{article} \usepackage{xstring} \newcommand\foo[1]{\StrSubstitute{#1}{love}{hate}} \begin{document} \section*{\foo{I love Mondays}} \end{document} if I ...
6
votes
1answer
156 views

Can I define a variable that contains a URL (youtube) and call \includemedia with it?

I can successfully embed a video in my latex file using a syntax like this: \documentclass[10pt,letterpaper]{book} \usepackage[latin1]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} ...
6
votes
1answer
325 views

\StrLeft has no effect on \citetitle

\footfullcite uses too much space so I decided to define a own command. I called it \footshortcite. It only display a pre- and a post-Option and the Author with Year. However, I don't like that most ...