| 1 |
\documentclass[a4paper,article,oneside,10pt]{memoir} |
| 2 |
|
| 3 |
\usepackage[utf8]{inputenc} |
| 4 |
\usepackage[T1]{fontenc} |
| 5 |
\usepackage{babel} |
| 6 |
\usepackage{kpfonts,microtype} |
| 7 |
|
| 8 |
\usepackage{listings,xspace,showexpl} |
| 9 |
|
| 10 |
\usepackage[hidelinks]{hyperref} |
| 11 |
|
| 12 |
\frenchspacing |
| 13 |
|
| 14 |
|
| 15 |
\lstset{ |
| 16 |
language=[LaTeX]TeX, |
| 17 |
basicstyle=\ttfamily\small, |
| 18 |
commentstyle=\itshape\ttfamily\small, |
| 19 |
escapechar=\%, |
| 20 |
alsoletter={\\,0,1,2,3,4,5,6,7,8,9,'}, |
| 21 |
breaklines=true, |
| 22 |
breakindent={0pt}, |
| 23 |
captionpos=t, |
| 24 |
tabsize=2, |
| 25 |
inputencoding=utf8, |
| 26 |
extendedchars=true, |
| 27 |
mathescape=true, |
| 28 |
} |
| 29 |
|
| 30 |
\newcommand\strctttex{\texttt{stricttex}\xspace} |
| 31 |
|
| 32 |
\title{\strctttex\ -- strictly balanced brackets and numbers in command names (v0.2$\beta$)} |
| 33 |
\date{\today} |
| 34 |
\author{Sebastian \O rsted (\href{mailto:[email protected]}{[email protected]})} |
| 35 |
|
| 36 |
\hypersetup{ |
| 37 |
pdfauthor={Sebastian \O rsted}, |
| 38 |
pdftitle={leftindex -- left indices with better spacing}, |
| 39 |
} |
| 40 |
|
| 41 |
\begin{document} |
| 42 |
|
| 43 |
\maketitle |
| 44 |
|
| 45 |
\noindent |
| 46 |
The \strctttex package is a small, Lua\LaTeX-only package providing you with three, sometimes useful features: |
| 47 |
\begin{itemize} |
| 48 |
\item It allows you to make brackets \lstinline![...]! ``strict'', meaning that each~\lstinline![! |
| 49 |
must be balanced by a~\lstinline!]!. |
| 50 |
\item It allows you to use numbers in command names, so |
| 51 |
that you can do stuff like~\lstinline!\newcommand\pi12{\pi_{12}}!. |
| 52 |
\item It allows you to use numbers \emph{and} primes in command names, |
| 53 |
so that you can do stuff like~\lstinline!\newcommand\pi'12{\pi '_{12}}!. |
| 54 |
\end{itemize} |
| 55 |
|
| 56 |
\chapter*{Making brackets strict} |
| 57 |
|
| 58 |
The package provides the commands |
| 59 |
\begin{lstlisting} |
| 60 |
\StrictBracketsOn |
| 61 |
\StrictBracketsOff |
| 62 |
\end{lstlisting} |
| 63 |
Between these two commands, |
| 64 |
all left brackets~\lstinline![! are replaced by~\lstinline![$\{$!, |
| 65 |
and all right brackets~\lstinline!]! by~\lstinline!$\}$]!. This forces the brackets to be properly balanced. This is extremely useful in come packages, such as Seman\TeX, where you can then |
| 66 |
do things that would otherwise cause errors, e.g. |
| 67 |
\begin{lstlisting}[mathescape=false] |
| 68 |
\StrictBracketsOn |
| 69 |
$ \vf[upper=\vx[upper=2,lower=3]] $ |
| 70 |
\StrictBracketsOff |
| 71 |
\end{lstlisting} |
| 72 |
Normal brackets can still be accessed by using the standard \TeX\ commands |
| 73 |
\lstinline!\lbrack! and \lstinline!\rbrack!. |
| 74 |
The replacement algorithm has two important exceptions: |
| 75 |
\begin{itemize} |
| 76 |
\item \emph{No} replacements apply to the commands~\lstinline!\[...\]!, which can therefore be used as normal. |
| 77 |
\item If you absolute \emph{need} ordinary brackets, |
| 78 |
you can write \lstinline!<[>! and~\lstinline!<]>! to access them. This works |
| 79 |
in all contexts, so e.g. \lstinline!\<[>! and~\lstinline!\<]>! will work |
| 80 |
just like \lstinline!\[! and~\lstinline!\]!. |
| 81 |
\end{itemize} |
| 82 |
|
| 83 |
\newpage |
| 84 |
|
| 85 |
\chapter*{Allowing numbers (and possibly primes) in commands} |
| 86 |
|
| 87 |
The package provides the commands |
| 88 |
\begin{lstlisting} |
| 89 |
\NumbersInCommandsOn |
| 90 |
\NumbersInCommandsOff |
| 91 |
\NumbersAndPrimesInCommandsOn |
| 92 |
\NumbersAndPrimesInCommandsOff |
| 93 |
\end{lstlisting} |
| 94 |
The first pair of commands allows you to define commands containing numbers. So the following will work: |
| 95 |
\begin{lstlisting} |
| 96 |
\NumbersInCommandsOn |
| 97 |
\newcommand\pi12{\pi_{12}} |
| 98 |
\newcommand\pi13{\pi_{13}} |
| 99 |
\newcommand\pi23{\pi_{23}} |
| 100 |
\newcommand\pi12comma34{\pi_{12,34}} |
| 101 |
\NumbersInCommandsOff |
| 102 |
\end{lstlisting} |
| 103 |
Internally, what happens is that if a command is immediately followed by a number, |
| 104 |
that numbers is replaced by a text string, i.e. |
| 105 |
\lstinline!0!~gets replaced by~\lstinline!numberZERO!, |
| 106 |
\lstinline!1!~gets replaced by~\lstinline!numberONE!, |
| 107 |
etc. These long names have been chosen to prevent name clashes. |
| 108 |
In other words, the code that is eventually passed to \TeX\ is |
| 109 |
\begin{lstlisting} |
| 110 |
\newcommand\pinumberONEnumberTWO{\pi_{12}} |
| 111 |
\newcommand\pinumberONEnumberTHREE{\pi_{13}} |
| 112 |
\newcommand\pinumberTWOnumberTHREE{\pi_{23}} |
| 113 |
\newcommand\pinumberONEnumberTWOcommanumberTHREEnumberFOUR{\pi_{12,34}} |
| 114 |
\end{lstlisting} |
| 115 |
Needless to say, stuff like \lstinline!\kern11pt! will no longer work and will have to be |
| 116 |
replaced by~\lstinline!\kern 11pt!. |
| 117 |
|
| 118 |
The commands \lstinline!\NumbersAndPrimesInCommandsOn! and~\lstinline!\...Off! work almost the same way, except they also allow |
| 119 |
you to use \emph{primes}. So the following will work: |
| 120 |
\begin{lstlisting} |
| 121 |
\NumbersAndPrimesInCommandsOn |
| 122 |
\newcommand\pi'12{\pi '_{12}} |
| 123 |
\NumbersAndPrimesInCommandsOff |
| 124 |
\end{lstlisting} |
| 125 |
Internally, the algorithm works as before, except the prime~\lstinline!'! gets |
| 126 |
replaced by \lstinline!symbolPRIME!. So what is eventually passed to \TeX\ is |
| 127 |
\begin{lstlisting} |
| 128 |
\newcommand\pisymbolPRIMEnumberONEnumberTWO{\pi '_{12}} |
| 129 |
\end{lstlisting} |
| 130 |
|
| 131 |
|
| 132 |
\end{document} |