@@ -103,6 +103,13 @@ def _tex(s):
103103 return s
104104
105105
106+ # Standalone tokens that are ASCII shorthand for Angstrom in McStas
107+ # comp/instr headers -- "AA" is the dominant convention, but "Angs",
108+ # "Ang", "Angstrom"/"Angstroms" also appear. All are converted to the
109+ # proper LaTeX \AA{} (ring-A) symbol; see _tex_with_angstrom() below.
110+ _ANGSTROM_RE = re .compile (r'\b(?:AA|Angstroms?|Angs?)\b' )
111+
112+
106113# ------------------------------------------------------------------
107114# %D "Description" field -> flowing LaTeX (instead of one big
108115# \verbatim block), with a small, whitelisted set of embedded HTML
@@ -201,14 +208,15 @@ def repl_img(m):
201208 # single space, exactly like ordinary paragraph reflow.
202209 s = re .sub (r'\s+' , ' ' , s ).strip ()
203210
204- # Standalone "AA" (Angstrom) tokens -> \AA{}. Detected here, on the
205- # raw text (with only tag-derived placeholders interspersed, which
206- # can't create false word boundaries), and stashed via the *same*
207- # top-level tokens list as everything else above -- this is safe
208- # because it is a sibling top-level substitution into s, not nested
209- # inside another not-yet-resolved stashed value (contrast with
210- # _tex_with_angstrom(), which is for standalone/isolated use).
211- s = re .sub (r'\bAA\b' , lambda m : stash (r'\AA{}' ), s )
211+ # Standalone "AA"/"Angs"/"Ang"/"Angstrom(s)" (Angstrom) tokens -> \AA{}.
212+ # Detected here, on the raw text (with only tag-derived placeholders
213+ # interspersed, which can't create false word boundaries), and
214+ # stashed via the *same* top-level tokens list as everything else
215+ # above -- this is safe because it is a sibling top-level
216+ # substitution into s, not nested inside another not-yet-resolved
217+ # stashed value (contrast with _tex_with_angstrom(), which is for
218+ # standalone/isolated use).
219+ s = _ANGSTROM_RE .sub (lambda m : stash (r'\AA{}' ), s )
212220
213221 # Escape everything else exactly like normal LaTeX text (this also
214222 # correctly turns any *unrecognized* '<tag>' into literal, visible
@@ -278,12 +286,13 @@ def _mccode_label():
278286
279287def _tex_with_angstrom (s ):
280288 r'''
281- Like _tex(), but additionally converts standalone "AA" tokens -- the
282- common ASCII shorthand for Angstrom used throughout McStas comp/instr
283- headers, since the actual \AA{} (Angstrom, ring-A) character is rarely
284- typed directly -- into the proper LaTeX \AA{} symbol.
289+ Like _tex(), but additionally converts standalone Angstrom shorthand
290+ tokens -- "AA" is the dominant convention in McStas comp/instr
291+ headers, but "Angs", "Ang", "Angstrom"/"Angstroms" also appear, since
292+ the actual \AA{} (Angstrom, ring-A) character is rarely typed directly
293+ -- into the proper LaTeX \AA{} symbol.
285294
286- The "AA" detection deliberately happens on the *raw*, not-yet-escaped
295+ The token detection deliberately happens on the *raw*, not-yet-escaped
287296 text (protected via a stash/placeholder, exactly like
288297 _convert_inline_markup does for HTML tags) rather than after _tex()
289298 has run. This matters: in raw text, '_' is a word character, so
@@ -304,7 +313,7 @@ def _tex_with_angstrom(s):
304313 def stash (repl ):
305314 tokens .append (repl )
306315 return '\x01 %d\x02 ' % (len (tokens ) - 1 )
307- s = re .sub (r'\bAA\b' , lambda m : stash (r'\AA{}' ), s )
316+ s = _ANGSTROM_RE .sub (lambda m : stash (r'\AA{}' ), s )
308317 s = _tex (s )
309318 def restore (m ):
310319 return tokens [int (m .group (1 ))]
0 commit comments