-
Notifications
You must be signed in to change notification settings - Fork 1
/
txt2latex.perl
executable file
·107 lines (86 loc) · 2.89 KB
/
txt2latex.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl -w
=head1 txt file format
B<~> means unbreakable space. Use B<\~> to escape tilde.
B<Empty line> means new paragraph.
B<//> means line break.
B<"> are changed to lower and upper quotes. Similarly, B<'>,
B<E<lt>E<lt>> and B<E<gt>E<gt>>. B<'> can be escaped by B<\'>.
B<--> means m-dash.
B<{~n}> means n with tilde. You can use B<`'"v/^o> instead of B<~> to
mark grave, acute, umlaut, caron, slash, circumflex, ring.
B<\x> means the "times" sign.
B<$> means right-aligned paragraph. Use backslash to escape.
B<# at the beginning of a line> means a comment.
B<## and nothing else> means beginning of the comment section at
the end of the document.
B</>textB</> means text in italics. Use backslash to escape.
B<*>textB<*> means text in bold. Use backslash to escape.
B<^>textB<^> means superscript. Use backslash to escape.
B<_>textB<_> means section name. Use backslash to escape.
B<||> text B<||> means centered text.
B<==> text B<==> means title.
=cut
use open IN => ':encoding(iso-8859-2)';
binmode STDOUT, ':utf8';
print<<EOH;
% LaTeX
\\documentclass[11pt,a4paper]{article}
\\usepackage{polyglossia}
\\setmainlanguage{czech}
\\addtolength\\oddsidemargin{-2cm}
\\addtolength\\textwidth{4cm}
\\addtolength\\topmargin{-2cm}
\\addtolength\\textheight{4cm}
\\sloppy
\\begin{document}
EOH
@specials{'~','`',"'",'"','v','^','u'}=('~','`',"'",'"','v ','^','u ');
$line=join'',<>;
$line=~s:&:\\&:g;
$line=~s:<<:«:g;
$line=~s:>>:»:g;
$line=~s:\.{3}:\\dots{}:g;
$line=~s:\\~:&TILDE;:g;
$line=~s:\\':&APOSTROPHE;:g;
#$line=~s:~: :g;
#$line=~s:^$:<p>:gm;
$line=~s://:\\\\:g;
$line=~s:(?<!<!)--(?!>):---:g;
#$line=~s:(?<!{)"([^"]+)":\{\},,\{\}$1\{\}``\{\}:g;#quotedblbase,textquotedblleft
$line=~s:(?<!{)"([^"]+)":\\quotedblbase\{\}$1\\textquotedblleft\{\}:g;
$line=~s:'([^']+)':,$1\{\}`:g;#quotesinglbase,textquoteleft
#$line=~s:,,:„:g;
#$line=~s:":“:g;
$line=~s:\\\$:&dolar;:g;
$line=~s:<:\$<\$:g;#\textless
$line=~s:>:\$>\$:g;#\textgreater
$line=~s:«:<<:g;
$line=~s:»:>>:g;
$line=~s/^\$/\\hfill{}/gm;
$line=~s|^##$|\\framebox{\\parbox{\\textwidth}{|m and $div=1;
$line=~s|^#(.*?)$|\\framebox{$1}|gm;
$line=~s:\\/:&slash;:g;
$line=~s:\\\*:*:g;
$line=~s:\\\^:&up;:g;
$line=~s:\\x:×:g;
$line=~s:\\_:&under;:g;
$line=~s:(?<![<{])/([^/]+)(?<![<{])/:\\textit{$1}:g;
$line=~s:\*([^*]+)\*:\\textbf{$1}:g;
$line=~s:\^([^^]+)\^:\$^{\\hbox{$1}}\$:g;
$line=~s:_([^_]+)_:\\subsection*{$1}:g;
$line=~s:==(.+?)==:\\section*{$1}:g;
$line=~s:\|\|([^|]+?)\|\|:\\begin{center}\n$1\n\\end{center}:g;
$line=~s:&TILDE;:\\~{ }:g;
$line=~s:&APOSTROPHE;:':g;
$line=~s:&dolar;:\\\$:g;
$line=~s:&slash;:/:g;
$line=~s:*:*:g;
$line=~s:&up;:\$\\hat{~}\$:g;
$line=~s:&under;:\\_:g;
$line=~s:×:\$\\times\$:g;
$line=~s:{\\[oO]}:\\$1:g;
$line=~s:{o(([Aa]))}:\\$1$1:g;
$line=~s#{((.)(.))}#(exists $specials{$2}) ? "\\$specials{$2}$3" : "{$1}"#ge;
print$line;
print '}}' if $div;
print"\\end{document}";