aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-11-26 17:32:51 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-11-26 17:32:51 -0500
commit18a0a8548ad241e8b44d472ba674fc86b3780e21 (patch)
tree9d0d3759b06848ce5b571924f15ac89b86ad5543 /src
parent39a10628b4de6937796e05564cd98d676a859c29 (diff)
downloadpostgresql-18a0a8548ad241e8b44d472ba674fc86b3780e21.tar.gz
postgresql-18a0a8548ad241e8b44d472ba674fc86b3780e21.zip
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 9a98984f4. Back-patch the code change to all supported versions.
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/print.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index a1d2e9709d1..c8f37fae5bd 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -2184,14 +2184,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);
@@ -2199,13 +2219,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: