Skip to content

Commit 74bfb53

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 0aa7e38 commit 74bfb53

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/bin/psql/print.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,28 +1579,52 @@ latex_escaped_print(const char *in, FILE *fout)
15791579
for (p = in; *p; p++)
15801580
switch (*p)
15811581
{
1582-
case '&':
1583-
fputs("\\&", fout);
1582+
/*
1583+
* We convert ASCII characters per the recommendations in
1584+
* Scott Pakin's "The Comprehensive LATEX Symbol List",
1585+
* available from CTAN. For non-ASCII, you're on your own.
1586+
*/
1587+
case '#':
1588+
fputs("\\#", fout);
1589+
break;
1590+
case '$':
1591+
fputs("\\$", fout);
15841592
break;
15851593
case '%':
15861594
fputs("\\%", fout);
15871595
break;
1588-
case '$':
1589-
fputs("\\$", fout);
1596+
case '&':
1597+
fputs("\\&", fout);
1598+
break;
1599+
case '<':
1600+
fputs("\\textless{}", fout);
1601+
break;
1602+
case '>':
1603+
fputs("\\textgreater{}", fout);
1604+
break;
1605+
case '\\':
1606+
fputs("\\textbackslash{}", fout);
1607+
break;
1608+
case '^':
1609+
fputs("\\^{}", fout);
15901610
break;
15911611
case '_':
15921612
fputs("\\_", fout);
15931613
break;
15941614
case '{':
15951615
fputs("\\{", fout);
15961616
break;
1617+
case '|':
1618+
fputs("\\textbar{}", fout);
1619+
break;
15971620
case '}':
15981621
fputs("\\}", fout);
15991622
break;
1600-
case '\\':
1601-
fputs("\\backslash", fout);
1623+
case '~':
1624+
fputs("\\~{}", fout);
16021625
break;
16031626
case '\n':
1627+
/* This is not right, but doing it right seems too hard */
16041628
fputs("\\\\", fout);
16051629
break;
16061630
default:

0 commit comments

Comments
 (0)