-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert4latexml.pl
executable file
·101 lines (101 loc) · 2.33 KB
/
convert4latexml.pl
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
use utf8;
use open ':encoding(utf8)';
use open ':std';
my $switch1;
while (<>) {
if ($switch1 && /\\makeatother/) {
$switch1 = 0;
next;
}
elsif ($switch1) {
next;
}
elsif (!$switch1 && /\\makeatletter/) {
$switch1 = 1;
next;
}
elsif (/\\documentclass/ && /jsbook/) {
s/jsbook[a-zA-Z0-9]*/book/;
s/titlepage, *//;
s/english, *//;
s/uplatex, *//;
s/, *titlepage//;
s/, *english//;
s/, *uplatex//;
s/\[ *titlepage *\]//;
s/\[ *english *\]//;
s/\[ *uplatex *\]//;
s/\[ *\]//;
}
elsif (/\\documentclass/ && /jsarticle/) {
s/jsarticle[a-zA-Z0-9]*/article/;
s/titlepage, *//;
s/english, *//;
s/uplatex, *//;
s/, *titlepage//;
s/, *english//;
s/, *uplatex//;
s/\[ *titlepage *\]//;
s/\[ *english *\]//;
s/\[ *uplatex *\]//;
s/\[ *\]//;
}
elsif (/\\usepackage/ && /xcolor/) {
s/dvipdfmx, *//;
s/hiresbb, *//;
s/, *dvipdfmx//;
s/, *hiresbb//;
s/\[ *dvipdfmx *\]//;
s/\[ *hiresbb *\]//;
s/\[ *\]//;
}
elsif (/\\bibliographystyle/ && /jecon/) {
s/jecon/alphanat/;
}
elsif (/\\usepackage/ && /(?:pxchfon|pxjahyper|pxcjkcat|otf)/) {
s/\\usepackage.*\{.+\}//;
}
#elsif (/\\includegraphics\{/) {
# s/\\includegraphics\{/\\includegraphics[scale=2.0]{/;
#}
#elsif (/\\title\{/) {
# s/\\title\{.+\}//;
#}
elsif (/\\cjkcategory\{/) {
s/\\cjkcategory\{.+\}//;
}
elsif (/\\centering/) {
s/\\centering//g;
}
elsif (/atbegshi/ || /AtBeginShipoutFirst/ || /prepartname/ || /postpartname/ || /prechaptername/ || /postchaptername/ || /presectionname/ || /postsectionname/ || /fullwidth/ || /evensidemargin/ || /oddsidemargin/ || /\\tableofcontents/ || /\\cleardoublepage/ || /\\clearpage/ || /\\maketitle/ || /\\pagenumbering\{roman\}/) {
s/^/\%/;
}
elsif (/\\bibliography\{([^\{\}]+)\}/) {
my $bibfile = $1;
$bibfile .= '.bbl';
my $thebibliography;
my $switch2;
open(BIB, "< $bibfile");
while (my $line = readline(BIB)) {
if ($line =~ /\\begin\{thebibliography\}/) {
$switch2 = 1;
}
elsif ($line =~ /\\end\{thebibliography\}/) {
$thebibliography .= $line;
last;
}
if ($switch2) {
$thebibliography .= $line;
}
}
close(BIB);
s/\\bibliography\{([^\{\}]+)\}/$thebibliography/;
}
elsif (/\\begin\{tabular\}\{.+\}/) {
s/p\{\d+(?:\.\d+)?[a-z]+\}/l/g;
}
elsif (/\\begin\{longtable\}(?:\[.+?\])\{.+\}/) {
s/p\{\d+(?:\.\d+)?[a-z]+\}/l/g;
}
print;
}