From 5070eac7251d96d4428b85779b66bcc67e8cab3d Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Wed, 25 Jul 2012 00:06:58 +0100 Subject: [PATCH] ENH Implement \string (except for escapechar) --- hex/Macros.lhs | 11 +++++++++++ hex/tests/expanded/string.hex | 1 + hex/tests/expanded/string.output | 1 + 3 files changed, 13 insertions(+) create mode 100644 hex/tests/expanded/string.hex create mode 100644 hex/tests/expanded/string.output diff --git a/hex/Macros.lhs b/hex/Macros.lhs index 8a8c65f..90ce42f 100644 --- a/hex/Macros.lhs +++ b/hex/Macros.lhs @@ -800,6 +800,17 @@ process1 (ControlSequence "\\expandafter") = do puttokenM unexp \end{code} +\begin{code} +process1 (ControlSequence "\\string") = do + unexp <- gettokenM + case unexp of + CharToken _ -> puttokenM unexp + ControlSequence csname -> mapM_ putC (reverse csname) + where + putC ' ' = puttokenM (CharToken (TypedChar ' ' Space)) + putC c = puttokenM (CharToken (TypedChar c Other)) +\end{code} + Manipulation of catcodes is performed here. It needs to change the token stream. In hex, the ``environment'' is actually a few separate namespaces, \tex{\\catcode} only manipulates the category table embedded in the tokens diff --git a/hex/tests/expanded/string.hex b/hex/tests/expanded/string.hex new file mode 100644 index 0000000..aad4608 --- /dev/null +++ b/hex/tests/expanded/string.hex @@ -0,0 +1 @@ +\string\test% diff --git a/hex/tests/expanded/string.output b/hex/tests/expanded/string.output new file mode 100644 index 0000000..e3909fc --- /dev/null +++ b/hex/tests/expanded/string.output @@ -0,0 +1 @@ +<\(12)>