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

Commit ac305ff

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 bd567b6 commit ac305ff

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
@@ -2188,28 +2188,52 @@ latex_escaped_print(const char *in, FILE *fout)
21882188
for (p = in; *p; p++)
21892189
switch (*p)
21902190
{
2191-
case '&':
2192-
fputs("\\&", fout);
2191+
/*
2192+
* We convert ASCII characters per the recommendations in
2193+
* Scott Pakin's "The Comprehensive LATEX Symbol List",
2194+
* available from CTAN. For non-ASCII, you're on your own.
2195+
*/
2196+
case '#':
2197+
fputs("\\#", fout);
2198+
break;
2199+
case '$':
2200+
fputs("\\$", fout);
21932201
break;
21942202
case '%':
21952203
fputs("\\%", fout);
21962204
break;
2197-
case '$':
2198-
fputs("\\$", fout);
2205+
case '&':
2206+
fputs("\\&", fout);
2207+
break;
2208+
case '<':
2209+
fputs("\\textless{}", fout);
2210+
break;
2211+
case '>':
2212+
fputs("\\textgreater{}", fout);
2213+
break;
2214+
case '\\':
2215+
fputs("\\textbackslash{}", fout);
2216+
break;
2217+
case '^':
2218+
fputs("\\^{}", fout);
21992219
break;
22002220
case '_':
22012221
fputs("\\_", fout);
22022222
break;
22032223
case '{':
22042224
fputs("\\{", fout);
22052225
break;
2226+
case '|':
2227+
fputs("\\textbar{}", fout);
2228+
break;
22062229
case '}':
22072230
fputs("\\}", fout);
22082231
break;
2209-
case '\\':
2210-
fputs("\\backslash", fout);
2232+
case '~':
2233+
fputs("\\~{}", fout);
22112234
break;
22122235
case '\n':
2236+
/* This is not right, but doing it right seems too hard */
22132237
fputs("\\\\", fout);
22142238
break;
22152239
default:

0 commit comments

Comments
 (0)