# HG changeset patch # User Franz Glasner # Date 1778680646 -7200 # Node ID f20177032d2116aff6274b09a1b0b2df2659251d # Parent de7118d299e9068751058cd48b2f22b3b177457f A chapter about escaping rules diff -r de7118d299e9 -r f20177032d21 docs/lexer-algpseudocode.rst --- a/docs/lexer-algpseudocode.rst Wed May 13 15:56:58 2026 +0200 +++ b/docs/lexer-algpseudocode.rst Wed May 13 15:57:26 2026 +0200 @@ -252,11 +252,10 @@ * Parameters are separated from the keyword/command by a (possibly empty) run of space or TAB characters. This is true for required and optional parameters. - - .. todo:: Escaping +- Unrecognized commands typically result in a + :py:class:`pygments.token.Token.Error` token. - A single backslash yields a Generic.Error token when in - `default` and `expression` states. +More on escaping rules you can find in :ref:`this chapter `. Commands With Required Parameters @@ -491,6 +490,33 @@ .. note:: Explicit token types are **case-sensitive**. +.. _escaping-rules: + +Escaping Rules +============== + +The escape character is a backslash ``\``. + +A backslash can be escaped with ``\\`` and yields a single backslash token. + +Within parameters a closing curly brace ``}`` ends the current +parameters environment. +It must be escaped using ``\}`` if a closing curly brace is part of the +argument content. + +A single backslash yields a :py:class:`pygments.token.Token.Generic.Error` +token when in `default` and `expression` states. +Contrary---in `text` contexts a single backslash character that does not +introduce a command yields a normal text token. + +In all contexts a backslash that would normally introduce a known command +must be escaped if the content should not recognized as a command. + +Single- and double-quotes must be escaped also (``\"`` or ``\'``) in +`default` and `expression` contexts when they should not introduce a +string token. + + .. _customized-sphinx-lexers: Customized Lexers in Sphinx