14
votes
Typewriter Animation with Math
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\begin{document}
\Huge
\let~\pause
\frame{
P~y~t~h~a~g~o~r~e~a~n~\ $a^{~2}~+~b^{~2}~=~c^{~2}$
}
\end{document}
Another approach
\...
12
votes
Accepted
Macro for integrals, a problem with limits
The problem is, that your \temp in the tried fix is read as one token and not parsed correctly. Inserting a few \expandafters fixes this:
\documentclass{article}
\usepackage{amsmath}
\usepackage{...
12
votes
Accepted
First character of \ref{<label>}
\ref is unsuitable to retrieve the data, the command is robust and with hyperref is also contains code to create a link. Use the refcount package and its \getrefnumber command:
\documentclass{article}
...
12
votes
Accepted
Delete string up to last slash
If I understand well what do you want: to expand the last segment separated by slashes from the parameter, i.e. /foo/bar should expand to bar and /foo/bar/next should expand to next. You can define ...
11
votes
Macro for integrals, a problem with limits
The outer part is good.
For deciding whether * appears, I use \SplitArgument for at most one occurrence of *; this will produce two arguments, the second of which is -NoValue- in case no asterisk ...
11
votes
Accepted
Substring of filename in LaTeX
% File name: DoctorStrange.tex
\documentclass{article}
\usepackage{xstring}
\begin{document}
\StrBehind*{\jobname}{Doctor}% <---- Note the starred variant
\end{document}
gives
Certain TeX ...
11
votes
xstring - How to define a macro that removes final punctuation?
Easy with expl3:
\documentclass{article}
%\usepackage{xparse} % uncomment for LaTeX prior to 2020-10-01
\ExplSyntaxOn
\NewDocumentCommand{\removePunct}{m}
{
\tl_set:Nn \l_tmpa_tl { #1 }
\...
11
votes
What about "exotic" characters in xstring?
In UTF-8, non-ASCII characters take several bytes, and xstring's \StrLen might be counting these bytes... however, it seems to be something entirely different, as @SandyG noted.
The following example ...
10
votes
How insert a character at the begin of every line from a source code?
With listings you can redefine the numberstyle:
\documentclass{article}
\usepackage{listings}
\lstset{
language=tex,
basicstyle=\footnotesize\ttfamily\selectfont,
keepspaces=true,
numbers=...
10
votes
Accepted
Splitting Strings by Comma
listofitems is a powerful list parsing package. Your example is the simplest of its capability:
\documentclass{article}
\usepackage{listofitems}
\begin{document}
\def\pleaseHelp{I, am, confused}
\...
10
votes
Conditionally remove trailing period
If you want to use only TeX primitives then you can use this code:
\def\foo{f.o.o.\checknextdot}
\def\checknextdot{\futurelet\next\checknextdotA}
\def\checknextdotA{\let\nextA=\relax
\ifx\next.\def\...
9
votes
Accepted
String replacement in math mode
This is a great use case for the Expl3 sequence commands. Here's your macro using those:
\ExplSyntaxOn
\NewDocumentCommand{\mpath}{m}{
\seq_set_split:Nnn \l_tmpa_seq {-} {#1} % ❶
\seq_use:Nn \...
8
votes
Possible bug in xstring + pdfLaTeX
In luatex or xelatex ç is a simple character token like c, but in pdflatex it is a pair of tokens that expand to \c{c}. xstring by default passes its arguments through \edef which would break any ...
7
votes
Accepted
Extract First Character (allowing for extra grouping)
You should use the \StrRemoveBraces before \StrChar:
\newcommand*{\ExtractFirstChar}[1]{%
\StrRemoveBraces{#1}[\FirstChar]%
\StrChar{\FirstChar}{1}[\FirstChar]%
First char of '#1' is '\...
7
votes
Accepted
Macro expansion inside \href
Expand the string substitution first by storing it in an argument, which you can then use with hyperref's \href:
\documentclass{article}
\usepackage{xstring}
\usepackage{hyperref}
\newcommand\phone[...
7
votes
String replacement in math mode
You might do
\newcommand{\mpath}[1]{%
\begingroup\noexpandarg
\StrSubstitute{#1}{-}{\text{-}}%
\endgroup
}
so to inhibit the full expansion of arguments performed by xstring.
A simple solution ...
7
votes
Accepted
xstring - How to define a macro that removes final punctuation?
For the sake of variety, let's also consider a LuaLaTeX-based solution. It defines a LaTeX utility macro called \RemovePunct, which in turn calls a Lua function called removepunct to do most of the ...
7
votes
Accepted
Possible bug in xstring + pdfLaTeX
Not a bug. You may use \noexpandarg, but there are other ways.
You can reimplement most (all) of xstring in expl3. Here's \StrCut:
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\xStrCut}{...
7
votes
String to lowercase and replace spaces with underscore
You can use expl3 that's more robust than xstring (and more flexible).
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\filter}{m}
{
\tabraham_filter:n { #1 }
}
\tl_new:N \...
7
votes
What about "exotic" characters in xstring?
When dealing with -- as you put it -- "exotic" (but still single-glyph and utf8-encoded, right?) characters at a low level, it's best not to work with pdf(La)TeX; instead, do work with a TeX ...
7
votes
Delete string up to last slash
I think a listofitems approach is simpler.
\documentclass{article}
\usepackage{listofitems}
\setsepchar[,]{/}%
\newcommand\postslash[1]{\readlist\myparse{#1}\myparse[-1]}
\begin{document}
\postslash{/...
7
votes
Accepted
How to get the first three letters of today’s day of week?
datetime2 already has \DTMshortweekdayname for this, no need to reinvent the wheel.
\documentclass[english]{article}
\usepackage[calc]{datetime2}
\newcommand{\mytoday}{%
\...
6
votes
How insert a character at the begin of every line from a source code?
minted.sty uses fancyvrb.sty to typeset the minted environments. fancyvrb.sty provides a macro named \FancyVerbFormatLine to change individual line formatting. You can define your own macro for your ...
6
votes
Substring of filename in LaTeX
The characters in \jobname are “stringified”, which roughly means that your input Doctor (where the characters are letters) is not the same as the Doctor in \jobname (where they are nonletters).
You ...
6
votes
Accepted
extract number from \jobname as counter
There are two errors.
You can't use \StrBehind inside the argument to \setcounter
You need to set the counter to one less than the number you want, because \section steps it before typesetting the ...
6
votes
Accepted
Automatic index entry for multiword terms
You need to separate the splitting of the parts from the index making command.
\documentclass{book}
\usepackage{xstring,imakeidx}
\makeindex
\newcommand{\iterm}[1]{%
#1%
\IfSubStr{#1}{ }{%
\...
6
votes
Accepted
Assigning a value from xstring
You can't use \StrLeft inside the argument to \IfInteger. You're passing the instructions to build a string rather than the string.
Rather do
\StrLeft{#1}{1}[\test]
\IfInteger{\test}
{\...
6
votes
String replacement in math mode
For the sake of variety, here's a LuaLaTeX-based solution. It defines a LaTeX macro called \mpath, which replaces all instances of - with en-dashes with the help of Lua's powerful string.gsub string ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
xstring × 377macros × 81
strings × 62
expansion × 35
conditionals × 29
xparse × 19
tikz-pgf × 18
etoolbox × 16
tables × 13
errors × 13
hyperref × 12
biblatex × 10
cross-referencing × 10
expl3 × 9
catcodes × 8
xetex × 7
loops × 7
comma-separated-list × 7
text-manipulation × 6
parsing × 6
spacing × 5
pdftex × 5
color × 5
lists × 5
unicode × 5