Repository: ipython/ipython

Issue:
\001 and \002 non-printable characters  in docstrings can't be processed by latex
Hello,

While attempting to build the doc (`cd docs && make pdf`), the special characters at 
https://github.com/ipython/ipython/blob/e6432249582e05f438303ce73d082a0351bb383e/IPython/utils/coloransi.py#L77

cause the following error:

```
[...]
[649] [650] [651] [652] [653]

LaTeX Warning: Hyper reference `api/generated/IPython.testing.tools:IPython.testing.tools.AssertPrints' on page 654 undefined on input line 77077.

[654] [655] [656]

LaTeX Warning: Hyper reference `api/generated/IPython.utils.colorable:IPython.utils.colorable.Colorable' on page 657 undefined on input line 77444.

[657] [658]
! Text line contains an invalid character.
l.77706 This class is similar to TermColors, but the escapes are wrapped in ^^A
                                                                               
? 
! Emergency stop.
l.77706 This class is similar to TermColors, but the escapes are wrapped in ^^A
```
I tried editing them out of the coloransi.py source, but they remained in the sphinx-generated `ipython.tex` and still cause problems, so I'm a bit lost.

Thanks!


Discussion:
For some reason, the latex used to generate the doc at https://ipython.readthedocs.io/en/stable/api/generated/IPython.utils.coloransi.html#IPython.utils.coloransi.InputTermColors didn't have this fatal error, but the non-printable characters are, well, invisible. It may be because I had to switch to `xelatex` instead of the default `pdflatex` in my doc generation attempt, because of the presence of other Unicode characters that cause issues, such as in the contributor names found in `docs/source/whatsnew/version8.rst`, with `make pdf LATEX=xelatex PDFLATEX=xelatex` (and adding `texlive-fontspec`, `texlive-polyglossia` and other XeLaTeX-related packages to the build environment.

Resolving patch:
diff --git a/IPython/sphinxext/ipython_directive.py b/IPython/sphinxext/ipython_directive.py
--- a/IPython/sphinxext/ipython_directive.py
+++ b/IPython/sphinxext/ipython_directive.py
@@ -19,7 +19,7 @@
    In [1]: 1+1
 
    In [1]: import datetime
-      ...: datetime.datetime.now()
+      ...: datetime.date.fromisoformat('2022-02-22')
 
 It supports IPython construct that plain
 Python does not understand (like magics):
@@ -28,7 +28,7 @@
 
    In [0]: import time
 
-   In [0]: %timeit time.sleep(0.05)
+   In [0]: %pdoc time.sleep
 
 This will also support top-level async when using IPython 7.0+
 
diff --git a/IPython/utils/coloransi.py b/IPython/utils/coloransi.py
--- a/IPython/utils/coloransi.py
+++ b/IPython/utils/coloransi.py
@@ -74,8 +74,8 @@ class TermColors:
 class InputTermColors:
     """Color escape sequences for input prompts.
 
-    This class is similar to TermColors, but the escapes are wrapped in \001
-    and \002 so that readline can properly know the length of each line and
+    This class is similar to TermColors, but the escapes are wrapped in \\001
+    and \\002 so that readline can properly know the length of each line and
     can wrap lines accordingly.  Use this class for any colored text which
     needs to be used in input prompts, such as in calls to raw_input().
 


Test patch: