{strings} are sequences of characters (most commonly literal constants).
25
votes
5answers
979 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 ...
23
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 ...
20
votes
4answers
995 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 ...
17
votes
2answers
2k 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 ...
16
votes
3answers
902 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
502 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 ...
14
votes
3answers
206 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 ...
13
votes
3answers
332 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 ...
12
votes
7answers
815 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 ...
12
votes
2answers
591 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 ...
11
votes
3answers
618 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
2answers
611 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
4k 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 ...
10
votes
3answers
333 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
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, ...
8
votes
3answers
668 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
2answers
69 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
173 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
340 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
1answer
133 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 ...
7
votes
4answers
205 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 ...
7
votes
3answers
627 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
2answers
594 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 ...
7
votes
1answer
280 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
249 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
1answer
379 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 ...
6
votes
2answers
436 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
405 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
244 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
982 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
4answers
200 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}
...
6
votes
1answer
152 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 ...
6
votes
1answer
77 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
...
6
votes
1answer
174 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
1k 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?
6
votes
2answers
275 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
285 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 ...
5
votes
2answers
134 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 ...
5
votes
2answers
308 views
String test, with complicated arguments
I have a command \mycom{} which takes 1 argument. The command should perform a test on the argument and do something accordingly. For simple arguments, I can use \ifthenelse, but I need to consider ...
5
votes
2answers
148 views
Changing catcode for commercial at (@) inside a macro to get it matched in pattern.
This question is related to TikZ: pgfutil-common: pgfutil@in@ - how does it work? and is a result of coping with that problem. I've already read How to change #catcode in a macro, but it didn't help ...
5
votes
2answers
425 views
Error using \string
Consider
\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\begin{document}
\texttt{\string\iftrue}
%% \texttt =\long macro:
%% #1->\ifmmode
%% ...
5
votes
1answer
129 views
Substituting strings only when not bounded by letters or numbers
Using StrSubstitute from xstring I can find and replace matches. For e.g.:
\StrSubstitute{I like to eat fish.}{fish}{apples} gives "I like to eat apples."
\StrSubstitute{Do you want to ...
5
votes
1answer
397 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 ...
5
votes
2answers
203 views
Replace asterisk with nothing in string
I have a function which grabs cells out of a table and returns them. Many of these cells end with two asterisks, and I would not like these returned from the function if they are present. For ...
5
votes
1answer
55 views
Testing for commercial at (@) in a string [duplicate]
Possible Duplicate:
Changing catcode for commercial at (@) inside a macro to get it matched in pattern.
I want to test whether a string contains the @ sign. I came up with the following ...
5
votes
1answer
302 views
Performing String Manipulation on result of \cite{}
I would like to perform some string manipulation (using the xstring package) on the result of a \cite{} (the bib package is given to me, and wouldn't allow what I want to do without a major rewrite). ...
5
votes
1answer
103 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 ...
4
votes
3answers
310 views
Programmatically setting a counter to a substring
I'm trying to set a counter based on the name of the current job. I've got the number I need by doing something like \substring{\jobname}{5}{5}} using the stringstrings package, and if I just output ...
4
votes
1answer
55 views
String lowercase equality (newbie question)
i'd like to test if a string, once transformed into lowercase is equal to a given string. Here a MWE of what i'm talking about :
\documentclass[a4paper,10pt]{report}
\usepackage[francais]{babel}
...
4
votes
1answer
161 views
The command \string does not print curly braces of its argument
While printing the List of Symbols, I would like, in a draft, to print the definition commands as well. For instance, consider the following commands:
\providecommand{\perm}{\ensuremath{\pi}}
...
