Skip to main content
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 \...
Symbol 1's user avatar
  • 37k
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{...
Skillmon's user avatar
  • 63.2k
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} ...
Ulrike Fischer's user avatar
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 ...
wipet's user avatar
  • 75.9k
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 ...
egreg's user avatar
  • 1.2m
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 ...
Troy's user avatar
  • 13.8k
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 } \...
egreg's user avatar
  • 1.2m
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 ...
frougon's user avatar
  • 24.5k
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=...
Ulrike Fischer's user avatar
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} \...
Steven B. Segletes's user avatar
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\...
wipet's user avatar
  • 75.9k
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 \...
Don Hosek's user avatar
  • 14.2k
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 ...
David Carlisle's user avatar
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 '\...
quark64's user avatar
  • 86
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[...
Werner's user avatar
  • 610k
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 ...
egreg's user avatar
  • 1.2m
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 ...
Mico's user avatar
  • 519k
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}{...
egreg's user avatar
  • 1.2m
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 \...
egreg's user avatar
  • 1.2m
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 ...
Mico's user avatar
  • 519k
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{/...
Steven B. Segletes's user avatar
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}{% \...
gusbrs's user avatar
  • 14.3k
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 ...
Arash Esbati's user avatar
  • 7,491
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 ...
egreg's user avatar
  • 1.2m
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 ...
egreg's user avatar
  • 1.2m
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}{ }{% \...
egreg's user avatar
  • 1.2m
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} {\...
egreg's user avatar
  • 1.2m
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 ...
Mico's user avatar
  • 519k

Only top scored, non community-wiki answers of a minimum length are eligible