Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b352cf7

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 6a13def commit b352cf7

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/fe_utils/print.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,28 +2187,52 @@ latex_escaped_print(const char *in, FILE *fout)
21872187
for (p = in; *p; p++)
21882188
switch (*p)
21892189
{
2190-
case '&':
2191-
fputs("\\&", fout);
2190+
/*
2191+
* We convert ASCII characters per the recommendations in
2192+
* Scott Pakin's "The Comprehensive LATEX Symbol List",
2193+
* available from CTAN. For non-ASCII, you're on your own.
2194+
*/
2195+
case '#':
2196+
fputs("\\#", fout);
2197+
break;
2198+
case '$':
2199+
fputs("\\$", fout);
21922200
break;
21932201
case '%':
21942202
fputs("\\%", fout);
21952203
break;
2196-
case '$':
2197-
fputs("\\$", fout);
2204+
case '&':
2205+
fputs("\\&", fout);
2206+
break;
2207+
case '<':
2208+
fputs("\\textless{}", fout);
2209+
break;
2210+
case '>':
2211+
fputs("\\textgreater{}", fout);
2212+
break;
2213+
case '\\':
2214+
fputs("\\textbackslash{}", fout);
2215+
break;
2216+
case '^':
2217+
fputs("\\^{}", fout);
21982218
break;
21992219
case '_':
22002220
fputs("\\_", fout);
22012221
break;
22022222
case '{':
22032223
fputs("\\{", fout);
22042224
break;
2225+
case '|':
2226+
fputs("\\textbar{}", fout);
2227+
break;
22052228
case '}':
22062229
fputs("\\}", fout);
22072230
break;
2208-
case '\\':
2209-
fputs("\\backslash", fout);
2231+
case '~':
2232+
fputs("\\~{}", fout);
22102233
break;
22112234
case '\n':
2235+
/* This is not right, but doing it right seems too hard */
22122236
fputs("\\\\", fout);
22132237
break;
22142238
default:

0 commit comments

Comments
 (0)