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> and code>xdv</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 * Note that <code>xelatex</code> xdv format
15 * corresponds with the other converters dvi format.
16 *
17 * Created: Tue Oct 18 10:06:30 2016
18 *
19 * @author <a href="mailto:rei3ner@arcor.de">Ernst Reissner</a>
20 * @version 1.0
21 */
22 public enum LatexDev {
23
24 // lualatex creates pdf
25 pdf {
26 String getXFigInTexLanguage() {
27 return "pdftex";
28 }
29
30 String getGnuplotInTexLanguage() {
31 return "pdf";
32 }
33
34 String getInkscapeTexSuffix() {
35 return LatexPreProcessor.SUFFIX_PDFTEX;
36 }
37
38 String getGraphicsInTexSuffix() {
39 return LatexPreProcessor.SUFFIX_PDF;
40 }
41
42 String getLatexOutputFormat() {
43 return "pdf";
44 }
45
46 boolean isViaDvi() {
47 return false;
48 }
49
50 boolean isDefault() {
51 return true;
52 }
53
54 File latexTargetFile(LatexMainDesc desc, boolean isTypeXelatex) {
55 return desc.pdfFile;
56 }
57
58 },
59 // latex creates dvi but not with the given drivers.
60 // dvi can be created also with
61 // lualatex -output-format=dvi and also accordingly with
62 // pdflatex -output-format=dvi
63 // pdf is the default but can also be created with
64 // lualatex -output-format=pdf and also with
65 // pdflatex -output-format=pdf
66 // xdv (!) can be created with xelatex -no-pdf
67 // Without that option, i.e. by default, xelatex creates pdf like the other converter.
68 dvips {
69 String getXFigInTexLanguage() {
70 return "pstex";
71 }
72
73 String getGnuplotInTexLanguage() {
74 return "eps";
75 }
76
77 String getInkscapeTexSuffix() {
78 return LatexPreProcessor.SUFFIX_EPSTEX;
79 }
80
81 String getGraphicsInTexSuffix() {
82 return LatexPreProcessor.SUFFIX_EPS;
83 }
84
85 String getLatexOutputFormat() {
86 return "dvi";
87 }
88
89 boolean isViaDvi() {
90 return true;
91 }
92
93 boolean isDefault() {
94 return false;
95 }
96
97 File latexTargetFile(LatexMainDesc desc, boolean isTypeXelatex) {
98 return isTypeXelatex ? desc.xdvFile : desc.dviFile;
99 }
100
101 };
102
103 /**
104 * Returns the name of the language
105 * used by the {@link Settings#getFig2devCommand()}
106 * to specify graphic without ``special'' text of an xfig-picture.
107 * The converse is specified
108 * by {@link LatexPreProcessor#XFIG_TEX_LANGUAGE}.
109 * In fact, a file of that format is created which is
110 * embedded with <code>\includegraphics</code> in latex-code
111 * representing text.
112 */
113 abstract String getXFigInTexLanguage();
114
115 /**
116 * Returns the name of the language
117 * used by the {@link Settings#getGnuplotCommand()}
118 * to specify graphic without text of a gnuplot-picture.
119 * In fact, there is a file of that format
120 * embedded with <code>\includegraphics</code> in latex-code
121 * representing text.
122 */
123 abstract String getGnuplotInTexLanguage();
124
125 /**
126 * Returns file suffix for the tex part of the svg export
127 * created by the command {@link Settings#getSvg2devCommand()}.
128 */
129 abstract String getInkscapeTexSuffix();
130
131 /**
132 * Returns the suffix of the file to be
133 * embedded with <code>\includegraphics</code> in latex-code
134 * representing all but text.
135 * This is used for processing fig-files and for processing svg-files
136 * in {@link LatexPreProcessor#runFig2DevInTex(File, LatexDev)} and
137 * in {@link LatexPreProcessor#runSvg2Dev(File, LatexDev, boolean)},
138 * whereas for conversion of gnuplot-files,
139 * this suffix is set automatically.
140 * Note also that this is used to clear the created files
141 * in all three cases.
142 */
143 abstract String getGraphicsInTexSuffix();
144
145 /**
146 * Returns the name of the target language <code>latex2dev</code> uses
147 * to convert the latex files into.
148 * This is set via option <code>-output-format=</code>.
149 */
150 abstract String getLatexOutputFormat();
151
152 abstract boolean isViaDvi();
153
154 /**
155 * The format created without specific command line option.
156 * This is true just pdf.
157 * It is false for dvi like formats; besides dvi itself xdv.
158 */
159 abstract boolean isDefault();
160
161 /**
162 * Returns the target file of a LaTeX run.
163 * This has the suffix given by {@link #getLatexOutputFormat()}.
164 *
165 * @param desc
166 * the latex main description.
167 * @param isTypeXelatex
168 * This is relevant only for {@link #dvips}
169 * returning xdv or dvi.
170 * @return
171 * the latex target file.
172 * If <code>xxx.tex</code> is the latex main file,
173 * then the target file is <code>xxx.dvi</code>, <code>xxx.xdv</code>
174 * or <code>xxx.pdf</code>.
175 */
176 abstract File latexTargetFile(LatexMainDesc desc, boolean isTypeXelatex);
177
178 /**
179 * Invoked in settings.
180 *
181 * @param pdfViaDvi
182 * whether the switch {@link Settings#pdfViaDvi} is set.
183 * @return
184 * {@link LatexDev#dvips} if <code>pdfViaDvi</code>; else {@link LatexDev#pdf};
185 */
186 static LatexDev devViaDvi(boolean pdfViaDvi) {
187 LatexDev res = pdfViaDvi ? LatexDev.dvips : LatexDev.pdf;
188 assert res.isViaDvi() == pdfViaDvi;
189 return res;
190 }
191
192
193 }