-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tlp_latex_version.php
370 lines (302 loc) · 8.81 KB
/
create_tlp_latex_version.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
// create_tlp_latex_version.php. License: GPLv3
require('libtlp.php');
function exit_with_error($s) {
fwrite(STDERR, $s . PHP_EOL);
exit(1);
}
// set default location for settings file
$settings_file = dirname(__FILE__) . '/default_latex_settings.json';
// read alternative settings file from command line
if (isset($argv[1])) {
$settings_file = $argv[1];
}
// ensure settings file exists
if (!(file_exists($settings_file))) {
exit_with_error('Settings file ' . $settings_file . ' not found.');
}
// read settings
$settings = json_decode(file_get_contents($settings_file));
// ensure json parsing worked correctly
if (!(isset($settings->passes))) {
exit_with_error('Settings file ' . $settings_file . ' could not be properly parsed.');
}
$settings->fnDone = false;
$settings->isLastPass = true;
$settings->currPassNum = 0;
// read TLP json file
$tlp = json_decode(file_get_contents(dirname(__FILE__) . '/tlp_latex.json'));
if (!(isset($tlp->P1))) {
exit_with_error('JSON file with LaTeX markup could not be properly parsed.');
}
?>
%
% Created by create_tlp_latex_version.php script
% <?php echo date('d M Y H:i:s') . PHP_EOL; ?>
%
% Settings given in <?php
echo $settings_file . PHP_EOL;
$settings_text = json_encode($settings, JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
foreach (explode(PHP_EOL, $settings_text) as $line) {
echo '% ' . $line . PHP_EOL;
}
?>
\documentclass[oneside,openany,12pt]{book}
%
% For tracking changes
\newcommand{\version}{<?php echo get_version_num(); ?>}
%
% For unicode input
\usepackage[utf8]{inputenc}
%
% For English and German hyphenation patterns
\usepackage[german,english]{babel}
%
% Sets page dimensions and orientation:
\usepackage[<?php
if (substr($settings->papersize,0,1) == '{') {
echo 'papersize=' . $settings->papersize . ',';
} else {
echo 'paper=' . $settings->papersize . ',';
}
if ($settings->landscape) {
echo 'landscape,';
}
echo 'margin=' . $settings->margin;
?>]{geometry}
%
% Font commands
<?php echo $settings->fontcommand . PHP_EOL; ?>
%
% For the columns of Russell's intro
\usepackage{multicol}
\usepackage{enumitem}
%
% For the basic column-based set-up of the book:
\usepackage{parcolumns}
%
% For greater control over lines in truth-tables:
\usepackage{hhline}
%
% Used for s p a c e d German emphasis:
\usepackage{soulutf8}
%
% For greater math options:
\usepackage{amsmath}
%
% For hyphens in pseudo-proposition!
\usepackage{hyphenat}
%
% Improves typography in cramped quarters:
\usepackage[kerning=true]{microtype}
%
% Used to determine column widths
\usepackage{calc}
%
% Creative commons icons:
\usepackage{ccicons}
%
<?php if (!($settings->multicolumnLayout)) { ?>
%
% table of contents stuff
\usepackage{tocloft}
\tocloftpagestyle{empty}
\setlength{\cftbeforetoctitleskip}{0pt}
\setlength{\cftaftertoctitleskip}{4pt}
\renewcommand{\cfttoctitlefont}{\Large\bfseries}
\setlength{\cftbeforechapskip}{0.7\baselineskip}
<?php } ?>
%
% For graphics:
\usepackage{tikz}
\usetikzlibrary{arrows}
%
<?php if ($settings->useBookCoverImage) { ?>
% for cover image
\usepackage{eso-pic}
<?php } ?>
%
\usepackage{hyperref}
\hypersetup{
pdfauthor={Ludwig Wittgenstein},%
pdftitle={Tractatus Logico-Philosophicus},%
pdfsubject={Philosophy,Logic},%
colorlinks,%
linkcolor=blue
}
%
\title{Tractatus Logico-Philosophicus}
\author{Ludwig Wittgenstein}
\date{1922}
<?php
// insert file with custom latex commands
readfile(dirname(__FILE__) . '/tlp_latex_custom_commands.tex');
// commands for index, if needed
if ($settings->includeIndex) { ?>
% Formatting of the index
%
% Sets up indents for index
\setitemize[1]{label={},leftmargin=\parindent,itemindent=-1\parindent,nolistsep}
\setitemize[2]{label={},leftmargin=\parindent,itemindent=-1.5\parindent,nolistsep}
\setitemize[3]{label={},leftmargin=\parindent,itemindent=0pt,nolistsep}
%
% Codes for index entries
\newcommand{\indexentry}[1]{\item #1}
\newcommand{\indexsubentry}[1]{\begin{itemize} \item #1 \end{itemize}}
\newcommand{\indexsubsubentry}[1]{\begin{itemize} \item \begin{itemize} \item #1 \end{itemize} \end{itemize}}
\newcommand{\indexgap}{\bigskip}
<?php } ?>
%
\begin{document}
% no headers or footers at first
\pagestyle{empty}%
% sloppy mode reduces badboxes in tight quarters
\sloppy%
% zeroout to help with math spacing in chunks
\zeroout%
% get rid of stretch between paragraphs
\setlength{\parskip}{0pt}%
% more hyphens
\global\hyphenpenalty=100%
\hyphenation{pseu-do-prop-o-si-tion pseu-do-prop-o-si-tions}%
<?php if ($settings->includeCoverPage) { ?>
\begin{titlepage}
<?php if ($settings->useBookCoverImage) { ?>
\pdfbookmark{Cover page}{cp}\AddToShipoutPicture*{\put(0,0){\includegraphics*[scale=0.45,trim=8 40 0 0]{cover}}}%
\phantom{Cover image}
\newpage
<?php } ?>
\begin{center}
\phantom{x}
\vfill
\vfill
\begin{Huge}
Tractatus Logico-Philosophicus\par
\end{Huge}
\bigskip
\begin{LARGE}
Logisch-philosophische Abhandlung\par
\end{LARGE}
\bigskip
\begin{Large}
\textit{By Ludwig Wittgenstein}\par
\end{Large}
\vfill
\vfill
{First published by Kegan Paul (London), 1922.}
\medskip
\textsc{Side-by-side-by-side edition, version \version\ (\today),}\\
containing the original German, alongside both the Ogden/Ramsey, and Pears/McGuinness English translations.
Available at: \url{http://people.umass.edu/klement/tlp/}
\vfill
\phantom{x}
\end{center}
\end{titlepage}
\clearpage%
\pagestyle{empty}%
<?php } // end coverpage ?>
<?php if (!($settings->multicolumnLayout)) { ?>
\phantomsection%
\tableofcontents
<?php } ?>
<?php if ($settings->includeRussellsIntro) { ?>
%=============================================
% RUSSELL'S INTRODUCTION
%=============================================
\clearpage\phantomsection\addcontentsline{toc}{chapter}{Introduction (by Bertrand Russell)}%
<?php if ($settings->columnsForRussellsIntro >= 2) { ?>
\begin{multicols}{<?php echo $settings->columnsForRussellsIntro; ?>}[\section*{Introduction}By Bertrand Russell, F.\,R.\,S.]
<?php } else { ?>
\section*{Introduction}By Bertrand Russell, F.\,R.\,S.
\medskip
<?php } ?>
\selectlanguage{english}\noindent%
<?php
readfile(dirname(__FILE__) . '/tlp_russells_intro.tex');
if ($settings->columnsForRussellsIntro >= 2) {
?>
\end{multicols}
<?php } ?>
<?php } //end Russell intro ?>
\clearpage%
<?php if ($settings->includeDedicationPage) { ?>
\thispagestyle{empty}\phantomsection\addcontentsline{toc}{chapter}{Dedication page}\thispagestyle{empty}%
\begin{center}
\phantom{x}
\vfill
\begin{Huge}
Tractatus Logico-Philosophicus\par
\end{Huge}
\vfill
\vfill
{\textsc{Dedicated}}\\
{\textsc{to the Memory of My Friend}}
\medskip
\begin{Large}
\textsc{David H. Pinsent}\par
\end{Large}
\vfill
\vfill
{\germph{Motto}: \ldots und alles, was man weiss, nicht bloss rauschen und brausen geh{\"o}rt hat, l{\"a}sst sich in drei Worten sagen.}
{\quad\textsc{--K{\"u}rnberger.}}
\vfill
\phantom{x}
\end{center}
\clearpage%
<?php } //end dedication page ?>
<?php
// CORE OF BOOK HANDLED HERE
if ($settings->multicolumnLayout) {
multicolumn_version();
} else {
if ($settings->includeGerman) {
german_standalone_version();
}
if ($settings->includeOgden) {
ogden_standalone_version();
}
if ($settings->includePearsMcGuinness) {
pmc_standalone_version();
}
}
// end CORE ?>
<?php if ($settings->includeIndex) { ?>
\clearpage%
\phantomsection\addcontentsline{toc}{chapter}{Index}%
<?php if ($settings->ruleBetweenColumns) { ?>
\setlength{\columnseprule}{0.5pt}
<?php }
if ($settings->columnsForIndex >= 2) { ?>
\begin{multicols}{<?php echo $settings->columnsForIndex; ?>}[\section*{Index (Pears/McGuinness)}]
<?php } else { ?>
\section*{Index (Pears/McGuinness)}
<?php } ?>
<?php readfile(dirname(__FILE__) . '/index_note.tex'); ?>
\bigskip
\bigskip
\begin{itemize}
\raggedright
<?php insert_index(); ?>
\end{itemize}
<?php if ($settings->columnsForIndex >= 2) { ?>
\end{multicols}
<?php } ?>
<?php } // end of index ?>
<?php if ($settings->includeLicenseInfo) { ?>
\phantomsection\addcontentsline{toc}{chapter}{Edition notes}\bigskip
\raggedright
\noindent\hrulefill
\phantom{xx}
\noindent {\Huge \ccPublicDomainAlt}\ Ludwig Wittgenstein's \textit{Tractatus Logico-Philosophicus} is in the \textbf{Public Domain}.
\noindent See \url{http://creativecommons.org/licenses/publicdomain/}
\bigskip
\noindent {\Huge \ccLogo\ccAttribution\ccShareAlike}\ This typesetting (including \LaTeX\ code), by Kevin C.\ Klement, is licensed under a \textbf{Creative Commons Attribution---Share Alike 3.0 United States License}.
\noindent See \url{http://creativecommons.org/licenses/by-sa/3.0/us/}
<?php if ($settings->useBookCoverImage) { ?>
\bigskip
The cover includes the photo “Ladders” by dev null, licensed under a Creative Commons Attribution Non-Commercial Share-Alike 2.0 License.
<?php } ?>
\bigskip
\noindent Latest version available at: \url{http://people.umass.edu/klement/tlp/}
<?php } ?>
\end{document}