I want to replace all dots in a LaTeX document with a call to a macro. Just doing a search and replace on '.' won't help as this will not replace the dots generated by LaTeX, e.g. in section numbers, enumerates, ...
2 Answers
You can assign . a different catcode, thus make it active and then define a macro . like this:
\catcode`\.=13 % make "." active
\def.{Lalala}
(adapted from https://tex.stackexchange.com/a/40515/4012)
Note that this might get you into trouble. I don't know much about catcodes and active characters and the like, but redefining . smells like trouble.
This doesn't work for all periods in your text, though. I fixed the subsections and subsubsections and the numbered list. If you need another specific period to be replaced, let me know, I'll see what I can do.
\documentclass{article}
\usepackage{adforn}% just for the flower symbol, not necessary for the replacement of "."
\newcommand*{\period}{\adforn{60}} % replace \adforn{60} with whatever
% you want to have instead of "."
\catcode`\.=13 % make "." active
\def.{\period}
\renewcommand{\thesubsection}{\thesection\period\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection\period\arabic{subsubsection}}
\usepackage{enumitem}
\usepackage{lipsum}% just for the Lorem ipsum text
\begin{document}
\tableofcontents
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
\begin{enumerate}[label=\arabic*\period]
\item numbered list
\item \texttt{\textbackslash ldots}: \ldots
\end{enumerate}
\lipsum[1]
\end{document}

-
3Seems to work for most cases, but not when the
.is auto generated such as in\subsection{First Subsection}. – Peter Grill Jan 12 '12 at 03:04 -
5+1 for a neat solution -- "smells like trouble" is worth an upvote all on its own. – Brent.Longborough Jan 12 '12 at 10:10
-
1@PeterGrill: fixed for subsections and subsubsections (and numbered lists). – doncherry Jan 13 '12 at 18:08
That's not possible in a simple way. Making the dot active will not affect dots stored in macros before the catcode change. It works with \lipsum in the example of doncherry only because the package is loaded after the \catcode command – and doncherry has a lot chance that the dot is not used in lipsum in places (e.g. in a number) where the active dot would explode.
You should change the catcode of the dot only after \begin{document} and reset it at every place where the dot is used e.g. in a number.
To change the other dots you will have to carefully track down all commands that issues dots and redefine them.
Another way to replace every dot is to manipulate the fonts, but this isn't simple either as quite a lot fonts can be involved.
- 327,261
\let\mydot=. \catcode\.=13 \let.=\mydot` trick and it Failed, so I think that font manipulation would be the best bet. I would guess that virtual fonts would be something to look at, in which case this question might be of use: http://tex.stackexchange.com/q/25852/86 – Andrew Stacey Jan 12 '12 at 12:02