1 package eu.simuline.m2latex.core;
2
3 import java.io.File;
4
5 /**
6 * Enumeration of the (conversion of latex to a) target format, called a 'device'.
7 * Currently, there are two, <code>pdf</code> and <code>dvips</code>,
8 * the latter representing <code>dvi</code>
9 * but <code>html</code> and <code>odt</code> are also desirable.
10 * The backend also affects the natural graphic formats:
11 * Whereas for the backend <code>pdf</code>,
12 * also <code>pdf</code> is used,
13 * <code>dvips</code> uses postscript-based formats.
14 *
15 * Created: Tue Oct 18 10:06:30 2016
16 *
17 * @author <a href="mailto:rei3ner@arcor.de">Ernst Reissner</a>
18 * @version 1.0
19 */
20 public enum LatexDev {
21
22 // lualatex creates pdf
23 pdf {
24 String getXFigInTexLanguage() {
25 return "pdftex";
26 }
27 String getGnuplotInTexLanguage() {
28 return "pdf";
29 }
30 String getInkscapeTexSuffix() {
31 return LatexPreProcessor.SUFFIX_PDFTEX;
32 }
33 String getGraphicsInTexSuffix() {
34 return LatexPreProcessor.SUFFIX_PDF;
35 }
36 String getLatexOutputFormat() {
37 return "pdf";
38 }
39 boolean isViaDvi() {
40 return false;
41 }
42 File latexTargetFile(LatexProcessor.LatexMainDesc desc) {
43 return desc.pdfFile;
44 }
45 },
46 // latex creates dvi but not with the given drivers.
47 dvips {
48 String getXFigInTexLanguage() {
49 return "pstex";
50 }
51 String getGnuplotInTexLanguage() {
52 return "eps";
53 }
54 String getInkscapeTexSuffix() {
55 return LatexPreProcessor.SUFFIX_EPSTEX;
56 }
57 String getGraphicsInTexSuffix() {
58 return LatexPreProcessor.SUFFIX_EPS;
59 }
60 String getLatexOutputFormat() {
61 return "dvi";
62 }
63 boolean isViaDvi() {
64 return true;
65 }
66 File latexTargetFile(LatexProcessor.LatexMainDesc desc) {
67 return desc.dviFile;
68 }
69 };
70
71 /**
72 * Returns the name of the language
73 * used by the {@link Settings#getFig2devCommand()}
74 * to specify graphic without ``special'' text of an xfig-picture.
75 * The converse is specified
76 * by {@link LatexPreProcessor#XFIG_TEX_LANGUAGE}.
77 * In fact, a file of that format is created which is
78 * embedded with <code>\includegraphics</code> in latex-code
79 * representing text.
80 */
81 abstract String getXFigInTexLanguage();
82
83 /**
84 * Returns the name of the language
85 * used by the {@link Settings#getGnuplotCommand()}
86 * to specify graphic without text of a gnuplot-picture.
87 * In fact, there is a file of that format
88 * embedded with <code>\includegraphics</code> in latex-code
89 * representing text.
90 */
91 abstract String getGnuplotInTexLanguage();
92
93 /**
94 * Returns file suffix for the tex part of the svg export
95 * created by the command {@link Settings#getSvg2devCommand()}.
96 */
97 abstract String getInkscapeTexSuffix();
98
99 /**
100 * Returns the suffix of the file to be
101 * embedded with <code>\includegraphics</code> in latex-code
102 * representing all but text.
103 * This is used for processing fig-files and for processing svg-files
104 * in {@link LatexPreProcessor#runFig2DevInTex(File, LatexDev)} and
105 * in {@link LatexPreProcessor#runSvg2Dev(File, LatexDev, boolean)},
106 * whereas for conversion of gnuplot-files,
107 * this suffix is set automatically.
108 * Note also that this is used to clear the created files
109 * in all three cases.
110 */
111 abstract String getGraphicsInTexSuffix();
112
113 /**
114 * Returns the name of the target language <code>latex2dev</code> uses
115 * to convert the latex files into.
116 * This is set via option <code>-output-format=</code>.
117 */
118 abstract String getLatexOutputFormat();
119
120 abstract boolean isViaDvi();
121
122 /**
123 * Returns the target file of a LaTeX run.
124 * This has the suffix given by {@link #getLatexOutputFormat()}.
125 */
126 abstract File latexTargetFile(LatexProcessor.LatexMainDesc desc);
127
128 static LatexDev devViaDvi(boolean pdfViaDvi) {
129 LatexDev res = pdfViaDvi ? LatexDev.dvips : LatexDev.pdf;
130 assert res.isViaDvi() == pdfViaDvi;
131 return res;
132 }
133
134
135 }