summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2018-11-26 22:32:51 +0000
committerTom Lane2018-11-26 22:32:51 +0000
commitac305ff8c3dfe44d3441297f665ac3c602a87199 (patch)
tree8bafb0032891511d6e358da03529aeffd6dfcf65
parentbd567b6a4147531267a9d4f4edcc5c985f06e785 (diff)
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.
-rw-r--r--src/fe_utils/print.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index daa23d1955a..5b56d31faa3 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -2188,14 +2188,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);
@@ -2203,13 +2223,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: