Skip to content

Commit 70d7e50

Browse files
committed
Fix translation of special characters in psql's LaTeX output modes.
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 9a98984. Back-patch the code change to all supported versions.
1 parent 95dcb8f commit 70d7e50

File tree

3 files changed

+98
-74
lines changed

3 files changed

+98
-74
lines changed

src/fe_utils/print.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,28 +2301,52 @@ latex_escaped_print(const char *in, FILE *fout)
23012301
for (p = in; *p; p++)
23022302
switch (*p)
23032303
{
2304-
case '&':
2305-
fputs("\\&", fout);
2304+
/*
2305+
* We convert ASCII characters per the recommendations in
2306+
* Scott Pakin's "The Comprehensive LATEX Symbol List",
2307+
* available from CTAN. For non-ASCII, you're on your own.
2308+
*/
2309+
case '#':
2310+
fputs("\\#", fout);
2311+
break;
2312+
case '$':
2313+
fputs("\\$", fout);
23062314
break;
23072315
case '%':
23082316
fputs("\\%", fout);
23092317
break;
2310-
case '$':
2311-
fputs("\\$", fout);
2318+
case '&':
2319+
fputs("\\&", fout);
2320+
break;
2321+
case '<':
2322+
fputs("\\textless{}", fout);
2323+
break;
2324+
case '>':
2325+
fputs("\\textgreater{}", fout);
2326+
break;
2327+
case '\\':
2328+
fputs("\\textbackslash{}", fout);
2329+
break;
2330+
case '^':
2331+
fputs("\\^{}", fout);
23122332
break;
23132333
case '_':
23142334
fputs("\\_", fout);
23152335
break;
23162336
case '{':
23172337
fputs("\\{", fout);
23182338
break;
2339+
case '|':
2340+
fputs("\\textbar{}", fout);
2341+
break;
23192342
case '}':
23202343
fputs("\\}", fout);
23212344
break;
2322-
case '\\':
2323-
fputs("\\backslash", fout);
2345+
case '~':
2346+
fputs("\\~{}", fout);
23242347
break;
23252348
case '\n':
2349+
/* This is not right, but doing it right seems too hard */
23262350
fputs("\\\\", fout);
23272351
break;
23282352
default:

0 commit comments

Comments
 (0)