Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix translation of special characters in psql's LaTeX output modes.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 26 Nov 2018 22:32:51 +0000 (17:32 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 26 Nov 2018 22:32:51 +0000 (17:32 -0500)
latex_escaped_print() mistranslated \ and failed to provide any translation
for # ^ and ~, all of which would typically lead to LaTeX document syntax
errors.  In addition it didn't translate < > and |, which would typically
render as unexpected characters.

To some extent this represents shortcomings in ancient versions of LaTeX,
which if memory serves had no easy way to render these control characters
as ASCII text.  But that's been fixed for, um, decades.  In any case there
is no value in emitting guaranteed-to-fail output for these characters.

Noted while fooling with test cases added by commit 9a98984f4.  Back-patch
the code change to all supported versions.

src/bin/psql/print.c

index cc8cd1140c70d7e6a88d4426797380630d5624f2..8de3ac08fcca6b68e4c7c6caca1f71e6cb8ddf38 100644 (file)
@@ -1579,14 +1579,34 @@ latex_escaped_print(const char *in, FILE *fout)
    for (p = in; *p; p++)
        switch (*p)
        {
-           case '&':
-               fputs("\\&", fout);
+               /*
+                * We convert ASCII characters per the recommendations in
+                * Scott Pakin's "The Comprehensive LATEX Symbol List",
+                * available from CTAN.  For non-ASCII, you're on your own.
+                */
+           case '#':
+               fputs("\\#", fout);
+               break;
+           case '$':
+               fputs("\\$", fout);
                break;
            case '%':
                fputs("\\%", fout);
                break;
-           case '$':
-               fputs("\\$", fout);
+           case '&':
+               fputs("\\&", fout);
+               break;
+           case '<':
+               fputs("\\textless{}", fout);
+               break;
+           case '>':
+               fputs("\\textgreater{}", fout);
+               break;
+           case '\\':
+               fputs("\\textbackslash{}", fout);
+               break;
+           case '^':
+               fputs("\\^{}", fout);
                break;
            case '_':
                fputs("\\_", fout);
@@ -1594,13 +1614,17 @@ latex_escaped_print(const char *in, FILE *fout)
            case '{':
                fputs("\\{", fout);
                break;
+           case '|':
+               fputs("\\textbar{}", fout);
+               break;
            case '}':
                fputs("\\}", fout);
                break;
-           case '\\':
-               fputs("\\backslash", fout);
+           case '~':
+               fputs("\\~{}", fout);
                break;
            case '\n':
+               /* This is not right, but doing it right seems too hard */
                fputs("\\\\", fout);
                break;
            default: