4

I have a section of text that uses the mid-2000s online style of interspersing exclamation points with ones, for example (I’m sorry for the uninitiated):

Oh Draco!111111!1 Oh mi fuking gud Draco!1111

Semantically, those ones operate as exclamation points, but LaTeX doesn't know that. As described in questions “Is a period after an abbreviation the same as an end of sentence period?” and “What is the proper use of \@ (i.e., backslash-at)?” LaTeX uses the characters and their surroundings to determine interword versus intersentence spacing. Is there a way to change the character 1 to be treated as ! either throughout an entire document or within an environment? Preferably XeLaTeX-compatible.

Minimal Working Example:

\documentclass{article}

\usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{english}

\begin{document}

\noindent Hi!1 I am Dan. This is \TeX.\ \noindent Hi!! I am Dan. This is \TeX.

\end{document}

Image of above Minimal Working Example

Dan
  • 43

1 Answers1

7

Latex already makes 1 have catcode 12 (same as !) so you just need to specify the spacing via its space factor code.

The default \nonfrenchspacing has

\sfcode`\!3000

so you can specify

\sfcode`\1=3000

so that 1 followed by a space will get an end of sentence space.

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}

\begin{document}

This and that. One two three! Red yellow blue1 This and that1 One two three1 Red yellow blue1 This and that. One two three! Red yellow blue1 This and that. One two three! Red yellow blue1 This and that1 One two three1 Red yellow blue1 This and that. One two three! Red yellow blue1

\sfcode`\1=3000

This and that. One two three! Red yellow blue1 This and that1 One two three1 Red yellow blue1 This and that. One two three! Red yellow blue1 This and that. One two three! Red yellow blue1 This and that1 One two three1 Red yellow blue1 This and that. One two three! Red yellow blue1

\end{document}

David Carlisle
  • 757,742
  • 1
    This is perfect, I don't know how you answered so quickly. You mentioned that this was easy because 1 and ! are the same catcode. For people looking for this in the future, what would be the case if they were different, for instance trying to work with the character b? – Dan Jan 20 '21 at 23:04
  • @Dan well actually it would be the same for b if you wanted say & you'd have to stop it having the table cell meaning as well. – David Carlisle Jan 20 '21 at 23:12