|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.latex; |
|
19 |
| |
|
20 |
| import java.io.IOException; |
|
21 |
| import java.text.SimpleDateFormat; |
|
22 |
| import java.util.Date; |
|
23 |
| import java.util.HashMap; |
|
24 |
| import java.util.Map; |
|
25 |
| |
|
26 |
| import org.qedeq.kernel.base.list.Element; |
|
27 |
| import org.qedeq.kernel.base.list.ElementList; |
|
28 |
| import org.qedeq.kernel.base.module.Author; |
|
29 |
| import org.qedeq.kernel.base.module.AuthorList; |
|
30 |
| import org.qedeq.kernel.base.module.Axiom; |
|
31 |
| import org.qedeq.kernel.base.module.Chapter; |
|
32 |
| import org.qedeq.kernel.base.module.FunctionDefinition; |
|
33 |
| import org.qedeq.kernel.base.module.Header; |
|
34 |
| import org.qedeq.kernel.base.module.Import; |
|
35 |
| import org.qedeq.kernel.base.module.ImportList; |
|
36 |
| import org.qedeq.kernel.base.module.Latex; |
|
37 |
| import org.qedeq.kernel.base.module.LatexList; |
|
38 |
| import org.qedeq.kernel.base.module.LinkList; |
|
39 |
| import org.qedeq.kernel.base.module.LiteratureItem; |
|
40 |
| import org.qedeq.kernel.base.module.LiteratureItemList; |
|
41 |
| import org.qedeq.kernel.base.module.LocationList; |
|
42 |
| import org.qedeq.kernel.base.module.Node; |
|
43 |
| import org.qedeq.kernel.base.module.PredicateDefinition; |
|
44 |
| import org.qedeq.kernel.base.module.Proof; |
|
45 |
| import org.qedeq.kernel.base.module.Proposition; |
|
46 |
| import org.qedeq.kernel.base.module.Qedeq; |
|
47 |
| import org.qedeq.kernel.base.module.Rule; |
|
48 |
| import org.qedeq.kernel.base.module.Section; |
|
49 |
| import org.qedeq.kernel.base.module.SectionList; |
|
50 |
| import org.qedeq.kernel.base.module.Specification; |
|
51 |
| import org.qedeq.kernel.base.module.Subsection; |
|
52 |
| import org.qedeq.kernel.base.module.UsedByList; |
|
53 |
| import org.qedeq.kernel.base.module.VariableList; |
|
54 |
| import org.qedeq.kernel.bo.module.ModuleDataException; |
|
55 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
|
56 |
| import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor; |
|
57 |
| import org.qedeq.kernel.bo.visitor.QedeqNotNullTransverser; |
|
58 |
| import org.qedeq.kernel.dto.module.PredicateDefinitionVo; |
|
59 |
| import org.qedeq.kernel.trace.Trace; |
|
60 |
| import org.qedeq.kernel.utility.IoUtility; |
|
61 |
| import org.qedeq.kernel.utility.ReplaceUtility; |
|
62 |
| import org.qedeq.kernel.utility.TextOutput; |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| public final class Qedeq2Latex extends AbstractModuleVisitor { |
|
80 |
| |
|
81 |
| |
|
82 |
| private final QedeqNotNullTransverser transverser; |
|
83 |
| |
|
84 |
| |
|
85 |
| private final TextOutput printer; |
|
86 |
| |
|
87 |
| |
|
88 |
| private final QedeqBo qedeq; |
|
89 |
| |
|
90 |
| |
|
91 |
| private final String language; |
|
92 |
| |
|
93 |
| |
|
94 |
| private final String level; |
|
95 |
| |
|
96 |
| |
|
97 |
| private final Map predicateDefinitions = new HashMap(); |
|
98 |
| |
|
99 |
| |
|
100 |
| private final Map functionDefinitions = new HashMap(); |
|
101 |
| |
|
102 |
| |
|
103 |
| private int chapterNumber; |
|
104 |
| |
|
105 |
| |
|
106 |
| private int sectionNumber; |
|
107 |
| |
|
108 |
| |
|
109 |
| private String id; |
|
110 |
| |
|
111 |
| |
|
112 |
| private String title; |
|
113 |
| |
|
114 |
| |
|
115 |
| private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
10
| private Qedeq2Latex(final QedeqBo qedeq, final String globalContext,
|
|
127 |
| final TextOutput printer, final String language, final String level) { |
|
128 |
10
| this.qedeq = qedeq;
|
|
129 |
10
| this.transverser = new QedeqNotNullTransverser(globalContext, this);
|
|
130 |
10
| this.printer = printer;
|
|
131 |
10
| if (language == null) {
|
|
132 |
0
| this.language = "en";
|
|
133 |
| } else { |
|
134 |
10
| this.language = language;
|
|
135 |
| } |
|
136 |
10
| if (level == null) {
|
|
137 |
0
| this.level = "1";
|
|
138 |
| } else { |
|
139 |
10
| this.level = level;
|
|
140 |
| } |
|
141 |
10
| final PredicateDefinitionVo equal = new PredicateDefinitionVo();
|
|
142 |
| |
|
143 |
10
| equal.setArgumentNumber("2");
|
|
144 |
10
| equal.setName("equal");
|
|
145 |
10
| equal.setLatexPattern("#1 \\ = \\ #2");
|
|
146 |
10
| predicateDefinitions.put("equal_2", equal);
|
|
147 |
| |
|
148 |
10
| final PredicateDefinitionVo notEqual = new PredicateDefinitionVo();
|
|
149 |
10
| notEqual.setArgumentNumber("2");
|
|
150 |
10
| notEqual.setName("notEqual");
|
|
151 |
10
| notEqual.setLatexPattern("#1 \\ \\neq \\ #2");
|
|
152 |
10
| predicateDefinitions.put("notEqual_2", notEqual);
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
10
| public static void print(final String globalContext, final QedeqBo qedeq,
|
|
167 |
| final TextOutput printer, final String language, final String level) |
|
168 |
| throws ModuleDataException, IOException { |
|
169 |
10
| final Qedeq2Latex converter = new Qedeq2Latex(qedeq, globalContext, printer,
|
|
170 |
| language, level); |
|
171 |
10
| converter.printLatex();
|
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
10
| private final void printLatex() throws IOException, ModuleDataException {
|
|
182 |
10
| transverser.accept(qedeq);
|
|
183 |
10
| printer.flush();
|
|
184 |
10
| if (printer.checkError()) {
|
|
185 |
0
| throw printer.getError();
|
|
186 |
| } |
|
187 |
| } |
|
188 |
| |
|
189 |
10
| public final void visitEnter(final Qedeq qedeq) {
|
|
190 |
10
| printer.println("% -*- TeX:" + language.toUpperCase() + " -*-");
|
|
191 |
10
| printer.println("%%% ====================================================================");
|
|
192 |
10
| printer.println("%%% @LaTeX-file " + printer.getName());
|
|
193 |
10
| printer.println("%%% Generated at " + getTimestamp());
|
|
194 |
10
| printer.println("%%% ====================================================================");
|
|
195 |
10
| printer.println();
|
|
196 |
10
| printer.println(
|
|
197 |
| "%%% Permission is granted to copy, distribute and/or modify this document"); |
|
198 |
10
| printer.println("%%% under the terms of the GNU Free Documentation License, Version 1.2");
|
|
199 |
10
| printer.println("%%% or any later version published by the Free Software Foundation;");
|
|
200 |
10
| printer.println(
|
|
201 |
| "%%% with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts."); |
|
202 |
10
| printer.println();
|
|
203 |
10
| printer.println("\\documentclass[a4paper,german,10pt,twoside]{book}");
|
|
204 |
10
| if ("de".equals(language)) {
|
|
205 |
5
| printer.println("\\usepackage[german]{babel}");
|
|
206 |
| } else { |
|
207 |
5
| if (!"en".equals(language)) {
|
|
208 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
209 |
| } |
|
210 |
5
| printer.println("\\usepackage[english]{babel}");
|
|
211 |
| } |
|
212 |
10
| printer.println("\\usepackage{makeidx}");
|
|
213 |
10
| printer.println("\\usepackage{amsmath,amsthm,amssymb}");
|
|
214 |
10
| printer.println("\\usepackage{color}");
|
|
215 |
10
| printer.println("\\usepackage[bookmarks,bookmarksnumbered,bookmarksopen,");
|
|
216 |
10
| printer.println(" colorlinks,linkcolor=webgreen,pagebackref]{hyperref}");
|
|
217 |
10
| printer.println("\\definecolor{webgreen}{rgb}{0,.5,0}");
|
|
218 |
10
| printer.println("\\usepackage{graphicx}");
|
|
219 |
10
| printer.println("\\usepackage{xr}");
|
|
220 |
10
| printer.println("\\usepackage{epsfig,longtable}");
|
|
221 |
10
| printer.println("\\usepackage{tabularx}");
|
|
222 |
10
| printer.println();
|
|
223 |
10
| if ("de".equals(language)) {
|
|
224 |
5
| printer.println("\\newtheorem{thm}{Theorem}[chapter]");
|
|
225 |
5
| printer.println("\\newtheorem{cor}[thm]{Korollar}");
|
|
226 |
5
| printer.println("\\newtheorem{lem}[thm]{Lemma}");
|
|
227 |
5
| printer.println("\\newtheorem{prop}[thm]{Proposition}");
|
|
228 |
5
| printer.println("\\newtheorem{ax}{Axiom}");
|
|
229 |
5
| printer.println("\\newtheorem{rul}{Regel}");
|
|
230 |
5
| printer.println();
|
|
231 |
5
| printer.println("\\theoremstyle{definition}");
|
|
232 |
5
| printer.println("\\newtheorem{defn}[thm]{Definition}");
|
|
233 |
5
| printer.println("\\newtheorem{idefn}[thm]{Initiale Definition}");
|
|
234 |
5
| printer.println();
|
|
235 |
5
| printer.println("\\theoremstyle{remark}");
|
|
236 |
5
| printer.println("\\newtheorem{rem}[thm]{Bemerkung}");
|
|
237 |
5
| printer.println("\\newtheorem*{notation}{Notation}");
|
|
238 |
| } else { |
|
239 |
5
| if (!"en".equals(language)) {
|
|
240 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
241 |
| } |
|
242 |
5
| printer.println("\\newtheorem{thm}{Theorem}[chapter]");
|
|
243 |
5
| printer.println("\\newtheorem{cor}[thm]{Corollary}");
|
|
244 |
5
| printer.println("\\newtheorem{lem}[thm]{Lemma}");
|
|
245 |
5
| printer.println("\\newtheorem{prop}[thm]{Proposition}");
|
|
246 |
5
| printer.println("\\newtheorem{ax}{Axiom}");
|
|
247 |
5
| printer.println("\\newtheorem{rul}{Rule}");
|
|
248 |
5
| printer.println();
|
|
249 |
5
| printer.println("\\theoremstyle{definition}");
|
|
250 |
5
| printer.println("\\newtheorem{defn}[thm]{Definition}");
|
|
251 |
5
| printer.println("\\newtheorem{idefn}[thm]{Initial Definition}");
|
|
252 |
5
| printer.println();
|
|
253 |
5
| printer.println("\\theoremstyle{remark}");
|
|
254 |
5
| printer.println("\\newtheorem{rem}[thm]{Remark}");
|
|
255 |
5
| printer.println("\\newtheorem*{notation}{Notation}");
|
|
256 |
| } |
|
257 |
10
| printer.println();
|
|
258 |
10
| printer.println("\\addtolength{\\textheight}{7\\baselineskip}");
|
|
259 |
10
| printer.println("\\addtolength{\\topmargin}{-5\\baselineskip}");
|
|
260 |
10
| printer.println();
|
|
261 |
10
| printer.println("\\setlength{\\parindent}{0pt}");
|
|
262 |
10
| printer.println();
|
|
263 |
10
| printer.println("\\frenchspacing \\sloppy");
|
|
264 |
10
| printer.println();
|
|
265 |
10
| printer.println("\\makeindex");
|
|
266 |
10
| printer.println();
|
|
267 |
10
| printer.println();
|
|
268 |
| } |
|
269 |
| |
|
270 |
10
| public final void visitLeave(final Qedeq qedeq) {
|
|
271 |
10
| printer.println("\\backmatter");
|
|
272 |
10
| printer.println();
|
|
273 |
10
| printer.println("\\addcontentsline{toc}{chapter}{\\indexname} \\printindex");
|
|
274 |
10
| printer.println();
|
|
275 |
10
| printer.println("\\end{document}");
|
|
276 |
10
| printer.println();
|
|
277 |
| } |
|
278 |
| |
|
279 |
10
| public void visitEnter(final Header header) {
|
|
280 |
10
| final LatexList title = header.getTitle();
|
|
281 |
10
| printer.print("\\title{");
|
|
282 |
10
| printer.print(getLatexListEntry(title));
|
|
283 |
10
| printer.println("}");
|
|
284 |
10
| printer.println("\\author{");
|
|
285 |
10
| final AuthorList authors = qedeq.getHeader().getAuthorList();
|
|
286 |
10
| for (int i = 0; i < authors.size(); i++) {
|
|
287 |
10
| if (i > 0) {
|
|
288 |
0
| printer.println(", ");
|
|
289 |
| } |
|
290 |
10
| final Author author = authors.get(i);
|
|
291 |
10
| printer.print(author.getName().getLatex());
|
|
292 |
| |
|
293 |
| } |
|
294 |
10
| printer.println();
|
|
295 |
10
| printer.println("}");
|
|
296 |
10
| printer.println();
|
|
297 |
10
| printer.println("\\begin{document}");
|
|
298 |
10
| printer.println();
|
|
299 |
10
| printer.println("\\maketitle");
|
|
300 |
10
| printer.println();
|
|
301 |
10
| printer.println("\\setlength{\\parskip}{5pt plus 2pt minus 1pt}");
|
|
302 |
10
| printer.println("\\mbox{}");
|
|
303 |
10
| printer.println("\\vfill");
|
|
304 |
10
| printer.println();
|
|
305 |
10
| final String url = getUrl(header.getSpecification());
|
|
306 |
10
| if (url != null && url.length() > 0) {
|
|
307 |
10
| printer.println("\\par");
|
|
308 |
10
| if ("de".equals(language)) {
|
|
309 |
5
| printer.println("Die Quelle f{\"ur} dieses Dokument ist hier zu finden:");
|
|
310 |
| } else { |
|
311 |
5
| if (!"en".equals(language)) {
|
|
312 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
313 |
| } |
|
314 |
5
| printer.println("The source for this document can be found here:");
|
|
315 |
| } |
|
316 |
10
| printer.println("\\par");
|
|
317 |
10
| printer.println("\\url{" + getUrl(header.getSpecification()) + "}");
|
|
318 |
10
| printer.println();
|
|
319 |
| } |
|
320 |
| { |
|
321 |
10
| printer.println("\\par");
|
|
322 |
10
| if ("de".equals(language)) {
|
|
323 |
5
| printer.println("Die vorliegende Publikation ist urheberrechtlich gesch{\"u}tzt.");
|
|
324 |
| } else { |
|
325 |
5
| if (!"en".equals(language)) {
|
|
326 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
327 |
| } |
|
328 |
5
| printer.println("Copyright by the authors. All rights reserved.");
|
|
329 |
| } |
|
330 |
| } |
|
331 |
10
| final String email = header.getEmail();
|
|
332 |
10
| if (email != null && email.length() > 0) {
|
|
333 |
10
| final String emailUrl = "\\url{mailto:" + email + "}";
|
|
334 |
10
| printer.println("\\par");
|
|
335 |
10
| if ("de".equals(language)) {
|
|
336 |
5
| printer.println("Bei Fragen, Anregungen oder Bitte um Aufnahme in die Liste der"
|
|
337 |
| + " abh{\"a}ngigen Module schicken Sie bitte eine EMail an die Addresse " |
|
338 |
| + emailUrl); |
|
339 |
| } else { |
|
340 |
5
| if (!"en".equals(language)) {
|
|
341 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
342 |
| } |
|
343 |
5
| printer.println("If you have any questions, suggestions or want to add something"
|
|
344 |
| + " to the list of modules that use this one, please send an email to the" |
|
345 |
| + " address " + emailUrl); |
|
346 |
| } |
|
347 |
10
| printer.println();
|
|
348 |
| } |
|
349 |
10
| printer.println("\\setlength{\\parskip}{0pt}");
|
|
350 |
10
| printer.println("\\tableofcontents");
|
|
351 |
10
| printer.println();
|
|
352 |
10
| printer.println("\\setlength{\\parskip}{5pt plus 2pt minus 1pt}");
|
|
353 |
10
| printer.println();
|
|
354 |
| } |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
22
| private String getUrl(final Specification specification) {
|
|
363 |
22
| final LocationList list = specification.getLocationList();
|
|
364 |
22
| if (list == null || list.size() <= 0
|
|
365 |
| || list.get(0).getLocation().length() <= "http://a.b".length()) { |
|
366 |
2
| return "";
|
|
367 |
| } |
|
368 |
20
| String location = list.get(0).getLocation();
|
|
369 |
20
| if (!location.endsWith("/")) {
|
|
370 |
20
| location += "/";
|
|
371 |
| } |
|
372 |
20
| location += specification.getName();
|
|
373 |
20
| location += ".xml";
|
|
374 |
20
| return location;
|
|
375 |
| } |
|
376 |
| |
|
377 |
54
| public void visitEnter(final Chapter chapter) {
|
|
378 |
54
| printer.print("\\chapter");
|
|
379 |
54
| if (chapter.getNoNumber() != null && chapter.getNoNumber().booleanValue()) {
|
|
380 |
16
| printer.print("*");
|
|
381 |
| } |
|
382 |
54
| printer.print("{");
|
|
383 |
54
| printer.print(getLatexListEntry(chapter.getTitle()));
|
|
384 |
54
| final String label = "chapter" + chapterNumber;
|
|
385 |
54
| printer.println("} \\label{" + label + "} \\hypertarget{" + label + "}{}");
|
|
386 |
54
| if (chapter.getNoNumber() != null && chapter.getNoNumber().booleanValue()) {
|
|
387 |
16
| printer.println("\\addcontentsline{toc}{chapter}{"
|
|
388 |
| + getLatexListEntry(chapter.getTitle()) + "}"); |
|
389 |
| } |
|
390 |
54
| printer.println();
|
|
391 |
54
| if (chapter.getIntroduction() != null) {
|
|
392 |
54
| printer.println(getLatexListEntry(chapter.getIntroduction()));
|
|
393 |
54
| printer.println();
|
|
394 |
| } |
|
395 |
| } |
|
396 |
| |
|
397 |
54
| public void visitLeave(final Chapter chapter) {
|
|
398 |
54
| printer.println("%% end of chapter " + getLatexListEntry(chapter.getTitle()));
|
|
399 |
54
| printer.println();
|
|
400 |
54
| chapterNumber++;
|
|
401 |
54
| sectionNumber = 0;
|
|
402 |
| } |
|
403 |
| |
|
404 |
32
| public void visitLeave(final SectionList list) {
|
|
405 |
32
| printer.println();
|
|
406 |
| } |
|
407 |
| |
|
408 |
94
| public void visitEnter(final Section section) {
|
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
94
| printer.print("\\section{");
|
|
415 |
94
| printer.print(getLatexListEntry(section.getTitle()));
|
|
416 |
94
| final String label = "chapter" + chapterNumber + "_section" + sectionNumber;
|
|
417 |
94
| printer.println("} \\label{" + label + "} \\hypertarget{" + label + "}{}");
|
|
418 |
94
| printer.println(getLatexListEntry(section.getIntroduction()));
|
|
419 |
94
| printer.println();
|
|
420 |
| } |
|
421 |
| |
|
422 |
94
| public void visitLeave(final Section section) {
|
|
423 |
94
| sectionNumber++;
|
|
424 |
| } |
|
425 |
| |
|
426 |
46
| public void visitEnter(final Subsection subsection) {
|
|
427 |
| |
|
428 |
| |
|
429 |
| |
|
430 |
| |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
| |
|
435 |
46
| if (subsection.getTitle() != null) {
|
|
436 |
40
| printer.print("\\subsection{");
|
|
437 |
40
| printer.println(getLatexListEntry(subsection.getTitle()));
|
|
438 |
40
| printer.println("}");
|
|
439 |
| } |
|
440 |
46
| if (subsection.getId() != null) {
|
|
441 |
0
| printer.println("\\label{" + subsection.getId() + "} \\hypertarget{"
|
|
442 |
| + subsection.getId() + "}{}"); |
|
443 |
| } |
|
444 |
46
| printer.println(getLatexListEntry(subsection.getLatex()));
|
|
445 |
| } |
|
446 |
| |
|
447 |
46
| public void visitLeave(final Subsection subsection) {
|
|
448 |
46
| printer.println();
|
|
449 |
46
| printer.println();
|
|
450 |
| } |
|
451 |
| |
|
452 |
222
| public void visitEnter(final Node node) {
|
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
222
| printer.println("\\par");
|
|
459 |
222
| printer.println(getLatexListEntry(node.getPrecedingText()));
|
|
460 |
222
| printer.println();
|
|
461 |
222
| id = node.getId();
|
|
462 |
222
| title = null;
|
|
463 |
222
| if (node.getTitle() != null) {
|
|
464 |
114
| title = getLatexListEntry(node.getTitle());
|
|
465 |
| } |
|
466 |
| } |
|
467 |
| |
|
468 |
222
| public void visitLeave(final Node node) {
|
|
469 |
222
| printer.println();
|
|
470 |
222
| printer.println(getLatexListEntry(node.getSucceedingText()));
|
|
471 |
222
| printer.println();
|
|
472 |
222
| printer.println();
|
|
473 |
| } |
|
474 |
| |
|
475 |
36
| public void visitEnter(final Axiom axiom) {
|
|
476 |
36
| printer.println("\\begin{ax}" + (title != null ? "[" + title + "]" : ""));
|
|
477 |
36
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
478 |
36
| printFormula(axiom.getFormula().getElement());
|
|
479 |
36
| printer.println(getLatexListEntry(axiom.getDescription()));
|
|
480 |
36
| printer.println("\\end{ax}");
|
|
481 |
| } |
|
482 |
| |
|
483 |
110
| public void visitEnter(final Proposition proposition) {
|
|
484 |
110
| printer.println("\\begin{prop}" + (title != null ? "[" + title + "]" : ""));
|
|
485 |
110
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
486 |
110
| printTopFormula(proposition.getFormula().getElement(), id);
|
|
487 |
110
| printer.println(getLatexListEntry(proposition.getDescription()));
|
|
488 |
110
| printer.println("\\end{prop}");
|
|
489 |
| } |
|
490 |
| |
|
491 |
10
| public void visitEnter(final Proof proof) {
|
|
492 |
| |
|
493 |
| |
|
494 |
| |
|
495 |
| |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
10
| printer.println("\\begin{proof}");
|
|
501 |
10
| printer.println(getLatexListEntry(proof.getNonFormalProof()));
|
|
502 |
10
| printer.println("\\end{proof}");
|
|
503 |
| } |
|
504 |
| |
|
505 |
28
| public void visitEnter(final PredicateDefinition definition) {
|
|
506 |
28
| final StringBuffer define = new StringBuffer("$$" + definition.getLatexPattern());
|
|
507 |
28
| final VariableList list = definition.getVariableList();
|
|
508 |
28
| if (list != null) {
|
|
509 |
24
| for (int i = list.size() - 1; i >= 0; i--) {
|
|
510 |
38
| Trace.trace(this, "printPredicateDefinition", "replacing!");
|
|
511 |
38
| ReplaceUtility.replace(define, "#" + (i + 1), getLatex(list.get(i)));
|
|
512 |
| } |
|
513 |
| } |
|
514 |
28
| if (definition.getFormula() != null) {
|
|
515 |
24
| printer.println("\\begin{defn}" + (title != null ? "[" + title + "]" : ""));
|
|
516 |
24
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
517 |
24
| define.append("\\ :\\leftrightarrow \\ ");
|
|
518 |
24
| define.append(getLatex(definition.getFormula().getElement()));
|
|
519 |
| } else { |
|
520 |
4
| printer.println("\\begin{idefn}" + (title != null ? "[" + title + "]" : ""));
|
|
521 |
4
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
522 |
| } |
|
523 |
28
| define.append("$$");
|
|
524 |
28
| predicateDefinitions.put(definition.getName() + "_" + definition.getArgumentNumber(),
|
|
525 |
| definition); |
|
526 |
28
| Trace.param(this, "printPredicateDefinition", "define", define);
|
|
527 |
28
| printer.println(define);
|
|
528 |
28
| printer.println(getLatexListEntry(definition.getDescription()));
|
|
529 |
28
| if (definition.getFormula() != null) {
|
|
530 |
24
| printer.println("\\end{defn}");
|
|
531 |
| } else { |
|
532 |
4
| printer.println("\\end{idefn}");
|
|
533 |
| } |
|
534 |
| } |
|
535 |
| |
|
536 |
32
| public void visitEnter(final FunctionDefinition definition) {
|
|
537 |
32
| final StringBuffer define = new StringBuffer("$$" + definition.getLatexPattern());
|
|
538 |
32
| final VariableList list = definition.getVariableList();
|
|
539 |
32
| if (list != null) {
|
|
540 |
26
| for (int i = list.size() - 1; i >= 0; i--) {
|
|
541 |
36
| Trace.trace(this, "printFunctionDefinition", "replacing!");
|
|
542 |
36
| ReplaceUtility.replace(define, "#" + (i + 1), getLatex(list.get(i)));
|
|
543 |
| } |
|
544 |
| } |
|
545 |
32
| if (definition.getTerm() != null) {
|
|
546 |
32
| printer.println("\\begin{defn}" + (title != null ? "[" + title + "]" : ""));
|
|
547 |
32
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
548 |
32
| define.append("\\ := \\ ");
|
|
549 |
32
| define.append(getLatex(definition.getTerm().getElement()));
|
|
550 |
| } else { |
|
551 |
0
| printer.println("\\begin{idefn}" + (title != null ? "[" + title + "]" : ""));
|
|
552 |
0
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
553 |
| } |
|
554 |
32
| define.append("$$");
|
|
555 |
32
| functionDefinitions.put(definition.getName() + "_" + definition.getArgumentNumber(),
|
|
556 |
| definition); |
|
557 |
32
| Trace.param(this, "printFunctionDefinition", "define", define);
|
|
558 |
32
| printer.println(define);
|
|
559 |
32
| printer.println(getLatexListEntry(definition.getDescription()));
|
|
560 |
32
| if (definition.getTerm() != null) {
|
|
561 |
32
| printer.println("\\end{defn}");
|
|
562 |
| } else { |
|
563 |
0
| printer.println("\\end{idefn}");
|
|
564 |
| } |
|
565 |
| } |
|
566 |
| |
|
567 |
32
| public void visitLeave(final FunctionDefinition definition) {
|
|
568 |
| } |
|
569 |
| |
|
570 |
16
| public void visitEnter(final Rule rule) {
|
|
571 |
16
| printer.println("\\begin{rul}" + (title != null ? "[" + title + "]" : ""));
|
|
572 |
16
| printer.println("\\label{" + id + "} \\hypertarget{" + id + "}{}");
|
|
573 |
16
| printer.println(getLatexListEntry(rule.getDescription()));
|
|
574 |
16
| printer.println("\\end{rul}");
|
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
| |
|
582 |
| |
|
583 |
| |
|
584 |
| |
|
585 |
| |
|
586 |
| |
|
587 |
| |
|
588 |
| |
|
589 |
16
| if (rule.getProofList() != null) {
|
|
590 |
0
| for (int i = 0; i < rule.getProofList().size(); i++) {
|
|
591 |
0
| printer.println("\\begin{proof}");
|
|
592 |
0
| printer.println(getLatexListEntry(rule.getProofList().get(i)
|
|
593 |
| .getNonFormalProof())); |
|
594 |
0
| printer.println("\\end{proof}");
|
|
595 |
| } |
|
596 |
| } |
|
597 |
| } |
|
598 |
| |
|
599 |
16
| public void visitLeave(final Rule rule) {
|
|
600 |
| } |
|
601 |
| |
|
602 |
2
| public void visitEnter(final LinkList linkList) {
|
|
603 |
2
| if (linkList.size() <= 0) {
|
|
604 |
0
| return;
|
|
605 |
| } |
|
606 |
2
| if ("de".equals(language)) {
|
|
607 |
1
| printer.println("Basierend auf: ");
|
|
608 |
| } else { |
|
609 |
1
| if (!"en".equals(language)) {
|
|
610 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
611 |
| } |
|
612 |
1
| printer.println("Based on: ");
|
|
613 |
| } |
|
614 |
2
| for (int i = 0; i < linkList.size(); i++) {
|
|
615 |
2
| if (linkList.get(i) != null) {
|
|
616 |
2
| printer.print(" \\ref{" + linkList.get(i) + "}");
|
|
617 |
| } |
|
618 |
| }; |
|
619 |
2
| printer.println();
|
|
620 |
| } |
|
621 |
| |
|
622 |
4
| public void visitEnter(final LiteratureItemList list) {
|
|
623 |
4
| printer.println("\\begin{thebibliography}{99}");
|
|
624 |
| |
|
625 |
4
| if ("de".equals(language)) {
|
|
626 |
2
| printer.println("\\addcontentsline{toc}{chapter}{Literaturverzeichnis}");
|
|
627 |
| } else { |
|
628 |
2
| if (!"en".equals(language)) {
|
|
629 |
0
| printer.println("%%% TODO unknown language: " + language);
|
|
630 |
| } |
|
631 |
2
| printer.println("\\addcontentsline{toc}{chapter}{Bibliography}");
|
|
632 |
| } |
|
633 |
4
| final ImportList imports = qedeq.getHeader().getImportList();
|
|
634 |
4
| if (imports != null && imports.size() > 0) {
|
|
635 |
2
| printer.println();
|
|
636 |
2
| printer.println();
|
|
637 |
2
| printer.println("%% Used other QEDEQ modules:");
|
|
638 |
2
| for (int i = 0; i < imports.size(); i++) {
|
|
639 |
2
| final Import imp = imports.get(i);
|
|
640 |
2
| printer.print("\\bibitem{" + imp.getLabel() + "} ");
|
|
641 |
2
| final Specification spec = imp.getSpecification();
|
|
642 |
2
| printer.print(getLatex(spec.getName()));
|
|
643 |
2
| if (spec.getLocationList() != null && spec.getLocationList().size() > 0
|
|
644 |
| && spec.getLocationList().get(0).getLocation().length() > 0) { |
|
645 |
2
| printer.print(" ");
|
|
646 |
| |
|
647 |
| |
|
648 |
| |
|
649 |
2
| printer.print("\\url{" + spec.getLocationList().get(0).getLocation() + "}");
|
|
650 |
| } |
|
651 |
2
| printer.println();
|
|
652 |
| } |
|
653 |
2
| printer.println();
|
|
654 |
2
| printer.println();
|
|
655 |
2
| printer.println("%% Other references:");
|
|
656 |
2
| printer.println();
|
|
657 |
| } |
|
658 |
| } |
|
659 |
| |
|
660 |
4
| public void visitLeave(final LiteratureItemList list) {
|
|
661 |
4
| final UsedByList usedby = qedeq.getHeader().getUsedByList();
|
|
662 |
4
| if (usedby != null && usedby.size() > 0) {
|
|
663 |
2
| printer.println();
|
|
664 |
2
| printer.println();
|
|
665 |
2
| printer.println("%% QEDEQ modules that use this one:");
|
|
666 |
2
| for (int i = 0; i < usedby.size(); i++) {
|
|
667 |
2
| final Specification spec = usedby.get(i);
|
|
668 |
2
| printer.print("\\bibitem{" + spec.getName() + "} ");
|
|
669 |
2
| printer.print(getLatex(spec.getName()));
|
|
670 |
2
| final String url = getUrl(spec);
|
|
671 |
2
| if (url != null && url.length() > 0) {
|
|
672 |
0
| printer.print(" ");
|
|
673 |
0
| printer.print("\\url{" + url + "}");
|
|
674 |
| } |
|
675 |
2
| printer.println();
|
|
676 |
| } |
|
677 |
2
| printer.println();
|
|
678 |
2
| printer.println();
|
|
679 |
| } |
|
680 |
4
| printer.println("\\end{thebibliography}");
|
|
681 |
| } |
|
682 |
| |
|
683 |
20
| public void visitEnter(final LiteratureItem item) {
|
|
684 |
20
| printer.print("\\bibitem{" + item.getLabel() + "} ");
|
|
685 |
20
| printer.println(getLatexListEntry(item.getItem()));
|
|
686 |
20
| printer.println();
|
|
687 |
| } |
|
688 |
| |
|
689 |
| |
|
690 |
| |
|
691 |
| |
|
692 |
| |
|
693 |
| |
|
694 |
| |
|
695 |
| |
|
696 |
110
| private void printTopFormula(final Element element, final String mainLabel) {
|
|
697 |
110
| if (!element.isList() || !element.getList().getOperator().equals("AND")) {
|
|
698 |
76
| printFormula(element);
|
|
699 |
76
| return;
|
|
700 |
| } |
|
701 |
34
| final ElementList list = element.getList();
|
|
702 |
34
| printer.println("\\mbox{}");
|
|
703 |
34
| printer.println("\\begin{longtable}{{@{\\extracolsep{\\fill}}p{0.9\\linewidth}l}}");
|
|
704 |
34
| for (int i = 0; i < list.size(); i++) {
|
|
705 |
230
| String label = "";
|
|
706 |
230
| if (list.size() >= ALPHABET.length() * ALPHABET.length()) {
|
|
707 |
0
| label = "" + (i + 1);
|
|
708 |
| } else { |
|
709 |
230
| if (list.size() > ALPHABET.length()) {
|
|
710 |
72
| final int div = (i / ALPHABET.length());
|
|
711 |
72
| label = "" + ALPHABET.charAt(div);
|
|
712 |
| } |
|
713 |
230
| label += ALPHABET.charAt(i % ALPHABET.length());
|
|
714 |
| } |
|
715 |
| |
|
716 |
230
| printer.println("\\centering $" + getLatex(list.getElement(i)) + "$"
|
|
717 |
| + " & \\label{" + mainLabel + ":" + label + "} \\hypertarget{" + mainLabel + ":" |
|
718 |
| + label + "}{} \\mbox{\\emph{(" + label + ")}} " |
|
719 |
230
| + (i + 1 < list.size() ? "\\\\" : ""));
|
|
720 |
| } |
|
721 |
34
| printer.println("\\end{longtable}");
|
|
722 |
| } |
|
723 |
| |
|
724 |
| |
|
725 |
| |
|
726 |
| |
|
727 |
| |
|
728 |
| |
|
729 |
112
| private void printFormula(final Element element) {
|
|
730 |
112
| printer.println("\\mbox{}");
|
|
731 |
112
| printer.println("\\begin{longtable}{{@{\\extracolsep{\\fill}}p{\\linewidth}}}");
|
|
732 |
112
| printer.println("\\centering $" + getLatex(element) + "$");
|
|
733 |
112
| printer.println("\\end{longtable}");
|
|
734 |
| } |
|
735 |
| |
|
736 |
| |
|
737 |
| |
|
738 |
| |
|
739 |
| |
|
740 |
| |
|
741 |
| |
|
742 |
472
| private String getLatex(final Element element) {
|
|
743 |
472
| return getLatex(element, true);
|
|
744 |
| } |
|
745 |
| |
|
746 |
| |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
| |
|
751 |
| |
|
752 |
| |
|
753 |
3596
| private String getLatex(final Element element, final boolean first) {
|
|
754 |
3596
| final StringBuffer buffer = new StringBuffer();
|
|
755 |
3596
| if (element.isAtom()) {
|
|
756 |
0
| return element.getAtom().getString();
|
|
757 |
| } |
|
758 |
3596
| final ElementList list = element.getList();
|
|
759 |
3596
| if (list.getOperator().equals("PREDCON")) {
|
|
760 |
642
| final String identifier = list.getElement(0).getAtom().getString() + "_"
|
|
761 |
| + (list.size() - 1); |
|
762 |
| |
|
763 |
| |
|
764 |
642
| if (predicateDefinitions.containsKey(identifier)) {
|
|
765 |
642
| final PredicateDefinition definition = (PredicateDefinition)
|
|
766 |
| predicateDefinitions.get(identifier); |
|
767 |
642
| final StringBuffer define = new StringBuffer(definition.getLatexPattern());
|
|
768 |
642
| for (int i = list.size() - 1; i >= 1; i--) {
|
|
769 |
1038
| ReplaceUtility.replace(define, "#" + i, getLatex(list.getElement(i), false));
|
|
770 |
| } |
|
771 |
642
| buffer.append(define);
|
|
772 |
| } else { |
|
773 |
0
| buffer.append(identifier);
|
|
774 |
0
| buffer.append("(");
|
|
775 |
0
| for (int i = 1; i < list.size(); i++) {
|
|
776 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
777 |
0
| if (i + 1 < list.size()) {
|
|
778 |
0
| buffer.append(", ");
|
|
779 |
| } |
|
780 |
| } |
|
781 |
0
| buffer.append(")");
|
|
782 |
| } |
|
783 |
2954
| } else if (list.getOperator().equals("PREDVAR")) {
|
|
784 |
346
| final String identifier = list.getElement(0).getAtom().getString();
|
|
785 |
346
| buffer.append(identifier);
|
|
786 |
346
| if (list.size() > 1) {
|
|
787 |
50
| buffer.append("(");
|
|
788 |
50
| for (int i = 1; i < list.size(); i++) {
|
|
789 |
50
| buffer.append(getLatex(list.getElement(i), false));
|
|
790 |
50
| if (i + 1 < list.size()) {
|
|
791 |
0
| buffer.append(", ");
|
|
792 |
| } |
|
793 |
| } |
|
794 |
50
| buffer.append(")");
|
|
795 |
| } |
|
796 |
2608
| } else if (list.getOperator().equals("FUNCON")) {
|
|
797 |
480
| final String identifier = list.getElement(0).getAtom().getString() + "_"
|
|
798 |
| + (list.size() - 1); |
|
799 |
| |
|
800 |
| |
|
801 |
480
| if (functionDefinitions.containsKey(identifier)) {
|
|
802 |
480
| final FunctionDefinition definition = (FunctionDefinition)
|
|
803 |
| functionDefinitions.get(identifier); |
|
804 |
480
| final StringBuffer define = new StringBuffer(definition.getLatexPattern());
|
|
805 |
480
| for (int i = list.size() - 1; i >= 1; i--) {
|
|
806 |
566
| ReplaceUtility.replace(define, "#" + i, getLatex(list.getElement(i), false));
|
|
807 |
| } |
|
808 |
480
| buffer.append(define);
|
|
809 |
| } else { |
|
810 |
0
| buffer.append(identifier);
|
|
811 |
0
| buffer.append("(");
|
|
812 |
0
| for (int i = 1; i < list.size(); i++) {
|
|
813 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
814 |
0
| if (i + 1 < list.size()) {
|
|
815 |
0
| buffer.append(", ");
|
|
816 |
| } |
|
817 |
| } |
|
818 |
0
| buffer.append(")");
|
|
819 |
| } |
|
820 |
2128
| } else if (list.getOperator().equals("FUNVAR")) {
|
|
821 |
0
| final String identifier = list.getElement(0).getAtom().getString();
|
|
822 |
0
| buffer.append(identifier);
|
|
823 |
0
| if (list.size() > 1) {
|
|
824 |
0
| buffer.append("(");
|
|
825 |
0
| for (int i = 1; i < list.size(); i++) {
|
|
826 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
827 |
0
| if (i + 1 < list.size()) {
|
|
828 |
0
| buffer.append(", ");
|
|
829 |
| } |
|
830 |
| } |
|
831 |
0
| buffer.append(")");
|
|
832 |
| } |
|
833 |
2128
| } else if (list.getOperator().equals("VAR")) {
|
|
834 |
1364
| final String text = list.getElement(0).getAtom().getString();
|
|
835 |
| |
|
836 |
1364
| try {
|
|
837 |
1364
| final int index = Integer.parseInt(text);
|
|
838 |
0
| final String newText = "" + index;
|
|
839 |
0
| if (!text.equals(newText) || newText.startsWith("-")) {
|
|
840 |
0
| throw new NumberFormatException("This is no allowed number: " + text);
|
|
841 |
| } |
|
842 |
0
| switch (index) {
|
|
843 |
0
| case 1:
|
|
844 |
0
| return "x";
|
|
845 |
0
| case 2:
|
|
846 |
0
| return "y";
|
|
847 |
0
| case 3:
|
|
848 |
0
| return "z";
|
|
849 |
0
| case 4:
|
|
850 |
0
| return "u";
|
|
851 |
0
| case 5:
|
|
852 |
0
| return "v";
|
|
853 |
0
| case 6:
|
|
854 |
0
| return "w";
|
|
855 |
0
| default:
|
|
856 |
0
| return "x_" + (index - 6);
|
|
857 |
| } |
|
858 |
| } catch (NumberFormatException e) { |
|
859 |
| |
|
860 |
1364
| return text;
|
|
861 |
| } |
|
862 |
764
| } else if (list.getOperator().equals("AND") || list.getOperator().equals("OR")
|
|
863 |
| || list.getOperator().equals("EQUI") || list.getOperator().equals("IMPL")) { |
|
864 |
542
| final String infix;
|
|
865 |
542
| if (list.getOperator().equals("AND")) {
|
|
866 |
130
| infix = "\\ \\land \\ ";
|
|
867 |
412
| } else if (list.getOperator().equals("OR")) {
|
|
868 |
66
| infix = "\\ \\lor \\ ";
|
|
869 |
346
| } else if (list.getOperator().equals("EQUI")) {
|
|
870 |
168
| infix = "\\ \\leftrightarrow \\ ";
|
|
871 |
| } else { |
|
872 |
178
| infix = "\\ \\rightarrow \\ ";
|
|
873 |
| } |
|
874 |
542
| if (!first) {
|
|
875 |
308
| buffer.append("(");
|
|
876 |
| } |
|
877 |
542
| for (int i = 0; i < list.size(); i++) {
|
|
878 |
1096
| buffer.append(getLatex(list.getElement(i), false));
|
|
879 |
1096
| if (i + 1 < list.size()) {
|
|
880 |
554
| buffer.append(infix);
|
|
881 |
| } |
|
882 |
| } |
|
883 |
542
| if (!first) {
|
|
884 |
308
| buffer.append(")");
|
|
885 |
| } |
|
886 |
222
| } else if (list.getOperator().equals("FORALL") || list.getOperator().equals("EXISTS")
|
|
887 |
| || list.getOperator().equals("EXISTSU")) { |
|
888 |
88
| final String prefix;
|
|
889 |
88
| if (list.getOperator().equals("FORALL")) {
|
|
890 |
52
| prefix = "\\forall ";
|
|
891 |
36
| } else if (list.getOperator().equals("EXISTS")) {
|
|
892 |
30
| prefix = "\\exists ";
|
|
893 |
| } else { |
|
894 |
6
| prefix = "\\exists! ";
|
|
895 |
| } |
|
896 |
88
| buffer.append(prefix);
|
|
897 |
88
| for (int i = 0; i < list.size(); i++) {
|
|
898 |
180
| if (i != 0 || (i == 0 && list.size() <= 2)) {
|
|
899 |
176
| buffer.append(getLatex(list.getElement(i), false));
|
|
900 |
| } |
|
901 |
180
| if (i + 1 < list.size()) {
|
|
902 |
92
| buffer.append("\\ ");
|
|
903 |
| } |
|
904 |
180
| if (list.size() > 2 && i == 1) {
|
|
905 |
4
| buffer.append("\\ ");
|
|
906 |
| } |
|
907 |
| } |
|
908 |
134
| } else if (list.getOperator().equals("NOT")) {
|
|
909 |
70
| final String prefix = "\\neg ";
|
|
910 |
70
| buffer.append(prefix);
|
|
911 |
70
| for (int i = 0; i < list.size(); i++) {
|
|
912 |
70
| buffer.append(getLatex(list.getElement(i), false));
|
|
913 |
| } |
|
914 |
64
| } else if (list.getOperator().equals("CLASS")) {
|
|
915 |
64
| final String prefix = "\\{ ";
|
|
916 |
64
| buffer.append(prefix);
|
|
917 |
64
| for (int i = 0; i < list.size(); i++) {
|
|
918 |
128
| buffer.append(getLatex(list.getElement(i), false));
|
|
919 |
128
| if (i + 1 < list.size()) {
|
|
920 |
64
| buffer.append(" \\ | \\ ");
|
|
921 |
| } |
|
922 |
| } |
|
923 |
64
| buffer.append(" \\} ");
|
|
924 |
0
| } else if (list.getOperator().equals("CLASSLIST")) {
|
|
925 |
0
| final String prefix = "\\{ ";
|
|
926 |
0
| buffer.append(prefix);
|
|
927 |
0
| for (int i = 0; i < list.size(); i++) {
|
|
928 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
929 |
0
| if (i + 1 < list.size()) {
|
|
930 |
0
| buffer.append(", \\ ");
|
|
931 |
| } |
|
932 |
| } |
|
933 |
0
| buffer.append(" \\} ");
|
|
934 |
0
| } else if (list.getOperator().equals("QUANTOR_INTERSECTION")) {
|
|
935 |
0
| final String prefix = "\\bigcap";
|
|
936 |
0
| buffer.append(prefix);
|
|
937 |
0
| if (0 < list.size()) {
|
|
938 |
0
| buffer.append("{").append(getLatex(list.getElement(0), false)).append("}");
|
|
939 |
| } |
|
940 |
0
| for (int i = 1; i < list.size(); i++) {
|
|
941 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
942 |
0
| if (i + 1 < list.size()) {
|
|
943 |
0
| buffer.append(" \\ \\ ");
|
|
944 |
| } |
|
945 |
| } |
|
946 |
0
| buffer.append(" \\} ");
|
|
947 |
0
| } else if (list.getOperator().equals("QUANTOR_UNION")) {
|
|
948 |
0
| final String prefix = "\\bigcup";
|
|
949 |
0
| buffer.append(prefix);
|
|
950 |
0
| if (0 < list.size()) {
|
|
951 |
0
| buffer.append("{").append(getLatex(list.getElement(0), false)).append("}");
|
|
952 |
| } |
|
953 |
0
| for (int i = 1; i < list.size(); i++) {
|
|
954 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
955 |
0
| if (i + 1 < list.size()) {
|
|
956 |
0
| buffer.append(" \\ \\ ");
|
|
957 |
| } |
|
958 |
| } |
|
959 |
0
| buffer.append(" \\} ");
|
|
960 |
| } else { |
|
961 |
0
| buffer.append(list.getOperator());
|
|
962 |
0
| buffer.append("(");
|
|
963 |
0
| for (int i = 0; i < list.size(); i++) {
|
|
964 |
0
| buffer.append(getLatex(list.getElement(i), false));
|
|
965 |
0
| if (i + 1 < list.size()) {
|
|
966 |
0
| buffer.append(", ");
|
|
967 |
| } |
|
968 |
| } |
|
969 |
0
| buffer.append(")");
|
|
970 |
| } |
|
971 |
2232
| return buffer.toString();
|
|
972 |
| } |
|
973 |
| |
|
974 |
| |
|
975 |
| |
|
976 |
| |
|
977 |
| |
|
978 |
| |
|
979 |
10
| private String getTimestamp() {
|
|
980 |
10
| final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss,SSS");
|
|
981 |
10
| return formatter.format(new Date());
|
|
982 |
| } |
|
983 |
| |
|
984 |
| |
|
985 |
| |
|
986 |
| |
|
987 |
| |
|
988 |
| |
|
989 |
| |
|
990 |
| |
|
991 |
| |
|
992 |
1272
| private String getLatexListEntry(final LatexList list) {
|
|
993 |
1272
| if (list == null) {
|
|
994 |
396
| return "";
|
|
995 |
| } |
|
996 |
876
| for (int i = 0; i < list.size(); i++) {
|
|
997 |
1187
| if (language.equals(list.get(i).getLanguage())) {
|
|
998 |
639
| return getLatex(list.get(i));
|
|
999 |
| } |
|
1000 |
| } |
|
1001 |
| |
|
1002 |
237
| for (int i = 0; i < list.size(); i++) {
|
|
1003 |
237
| if (list.get(i).getLanguage() == null) {
|
|
1004 |
220
| return getLatex(list.get(i));
|
|
1005 |
| } |
|
1006 |
| } |
|
1007 |
17
| for (int i = 0; i < list.size(); i++) {
|
|
1008 |
17
| return "MISSING! OTHER: " + getLatex(list.get(i));
|
|
1009 |
| } |
|
1010 |
0
| return "MISSING!";
|
|
1011 |
| } |
|
1012 |
| |
|
1013 |
| |
|
1014 |
| |
|
1015 |
| |
|
1016 |
| |
|
1017 |
| |
|
1018 |
| |
|
1019 |
876
| private String getLatex(final Latex latex) {
|
|
1020 |
876
| if (latex == null || latex.getLatex() == null) {
|
|
1021 |
4
| return "";
|
|
1022 |
| } |
|
1023 |
872
| return escapeUmlauts(latex.getLatex());
|
|
1024 |
| } |
|
1025 |
| |
|
1026 |
| |
|
1027 |
| |
|
1028 |
| |
|
1029 |
| |
|
1030 |
| |
|
1031 |
| |
|
1032 |
4
| private String getLatex(final String text) {
|
|
1033 |
4
| final StringBuffer buffer = new StringBuffer(text);
|
|
1034 |
4
| IoUtility.deleteLineLeadingWhitespace(buffer);
|
|
1035 |
4
| ReplaceUtility.replace(buffer, "\\", "\\textbackslash");
|
|
1036 |
4
| ReplaceUtility.replace(buffer, "$", "\\$");
|
|
1037 |
4
| ReplaceUtility.replace(buffer, "&", "\\&");
|
|
1038 |
4
| ReplaceUtility.replace(buffer, "%", "\\%");
|
|
1039 |
4
| ReplaceUtility.replace(buffer, "#", "\\#");
|
|
1040 |
4
| ReplaceUtility.replace(buffer, "_", "\\_");
|
|
1041 |
4
| ReplaceUtility.replace(buffer, "{", "\\{");
|
|
1042 |
4
| ReplaceUtility.replace(buffer, "}", "\\}");
|
|
1043 |
4
| ReplaceUtility.replace(buffer, "~", "\\textasciitilde");
|
|
1044 |
4
| ReplaceUtility.replace(buffer, "^", "\\textasciicircum");
|
|
1045 |
4
| ReplaceUtility.replace(buffer, "<", "\\textless");
|
|
1046 |
4
| ReplaceUtility.replace(buffer, ">", "\\textgreater");
|
|
1047 |
4
| ReplaceUtility.replace(buffer, "\u00fc", "{\\\"u}");
|
|
1048 |
4
| ReplaceUtility.replace(buffer, "\u00f6", "{\\\"o}");
|
|
1049 |
4
| ReplaceUtility.replace(buffer, "\u00e4", "{\\\"a}");
|
|
1050 |
4
| ReplaceUtility.replace(buffer, "\u00dc", "{\\\"U}");
|
|
1051 |
4
| ReplaceUtility.replace(buffer, "\u00d6", "{\\\"O}");
|
|
1052 |
4
| ReplaceUtility.replace(buffer, "\u00c4", "{\\\"A}");
|
|
1053 |
4
| ReplaceUtility.replace(buffer, "\u00df", "{\\ss}");
|
|
1054 |
4
| return buffer.toString();
|
|
1055 |
| } |
|
1056 |
| |
|
1057 |
| |
|
1058 |
| |
|
1059 |
| |
|
1060 |
| |
|
1061 |
| |
|
1062 |
| |
|
1063 |
| |
|
1064 |
872
| private String escapeUmlauts(final String nearlyLatex) {
|
|
1065 |
872
| if (nearlyLatex == null) {
|
|
1066 |
0
| return "";
|
|
1067 |
| } |
|
1068 |
872
| final StringBuffer buffer = new StringBuffer(nearlyLatex);
|
|
1069 |
872
| IoUtility.deleteLineLeadingWhitespace(buffer);
|
|
1070 |
872
| ReplaceUtility.replace(buffer, "\u00fc", "{\\\"u}");
|
|
1071 |
872
| ReplaceUtility.replace(buffer, "\u00f6", "{\\\"o}");
|
|
1072 |
872
| ReplaceUtility.replace(buffer, "\u00e4", "{\\\"a}");
|
|
1073 |
872
| ReplaceUtility.replace(buffer, "\u00dc", "{\\\"U}");
|
|
1074 |
872
| ReplaceUtility.replace(buffer, "\u00d6", "{\\\"O}");
|
|
1075 |
872
| ReplaceUtility.replace(buffer, "\u00c4", "{\\\"A}");
|
|
1076 |
872
| ReplaceUtility.replace(buffer, "\u00df", "{\\ss}");
|
|
1077 |
872
| return buffer.toString();
|
|
1078 |
| } |
|
1079 |
| |
|
1080 |
| } |