View Javadoc
1   package eu.simuline.m2latex.core;
2   
3   // import java.io.File;
4   
5   /**
6    * Represents a file to be injected in goal <code>inj</code>. 
7    * Injection means that it is a resource of this software 
8    * but can be inserted (injected) at {@link Settings#texSrcDirectory}. 
9    * It is not injected if there is already a file with this name 
10   * and it cannot be ensured that it is this software which wrote it. 
11   * The mechanism to find out whether this is true is: reading the headline. 
12   * To that end, a specific headline is inserted. 
13   * It is preceeded with the comment sign {@link #commentStr()} 
14   * appropriate for the format of the file, mostly a hash sign. 
15   * The files for which {@link #doFilter()} return true, 
16   * as e.g. for <code>.latexmkrc</code>, are filtered 
17   * replacing parameter names of this software by current values. 
18   * This allows to synchronize the settings of this software 
19   * with the settings of <code>latexmk</code>. 
20   * Finally, if {@link #setExecutable()} tells so, 
21   * the resulting file is set executable, 
22   * as is appropriate for scripts like <code>instVScode4tex.sh</code>. 
23   */
24  public enum Injection {
25    /**
26     * The record file of latexmk. 
27     * This must be filtered 
28     * to be synchronized with the current settings 
29     * of this piece of software. 
30     */
31    latexmkrc {
32      String getFileName() {
33        return ".latexmkrc";
34      }
35  
36      boolean doFilter() {
37        return true;
38      }
39  
40      boolean hasShebang() {
41        return true;
42      }
43    },
44    /**
45     * The record file of chktex. 
46     * This is adapted to some use cases
47     * of this piece of software. 
48     */
49    chktexrc {
50      String getFileName() {
51        return ".chktexrc";
52      }
53  
54      boolean hasShebang() {
55        return false;
56      }
57    },
58    /**
59     * The installation script for extensions of VS Code 
60     * used for development of latex documents. 
61     */
62    vscodeExt {
63      String getFileName() {
64        return "instVScode4tex.sh";
65      }
66  
67      boolean setExecutable() {
68        return true;
69      }
70  
71      boolean hasShebang() {
72        return true;
73      }
74    },
75    /**
76     * Invokes the latex compiler configured with epoque time set to 0. 
77     */
78    ntlatex {
79      String getFileName() {
80        return "ntlatex";
81      }
82  
83      boolean setExecutable() {
84        return true;
85      }
86  
87      boolean hasShebang() {
88        return true;
89      }
90    },
91    /**
92     * Invokes pythontex and writes a log file. 
93     * This is needed only because the current version of pythontex does not write log files. 
94     * In future this shall change and so this injection will be superfluous. 
95     */
96    pythontexW {
97      String getFileName() {
98        return "pythontexW";
99      }
100 
101     boolean setExecutable() {
102       return true;
103     }
104 
105     boolean hasShebang() {
106       return true;
107     }
108   },
109   /**
110    * Invokes depythontex and writes a log file. 
111    * This is needed only because the current version of depythontex does not write log files. 
112    * In future this shall change and so this injection will be superfluous. 
113    */
114   depythontexW {
115     String getFileName() {
116       return "depythontexW";
117     }
118 
119     boolean setExecutable() {
120       return true;
121     }
122 
123     boolean hasShebang() {
124       return true;
125     }
126   },
127   /**
128    * Invokes a diff tool for PDF files 
129    * combining visual diff with <code>diff-pdf-visual</code> 
130    * with diffing of PDF metainfo provided by <code>pdfinfo</code>. 
131    */
132   vmdiff {
133     String getFileName() {
134       return "vmdiff";
135     }
136 
137     boolean setExecutable() {
138       return true;
139     }
140 
141     boolean hasShebang() {
142       return true;
143     }
144   },
145   /**
146    * A header file loading package <code>graphicx</code> 
147    * with the appropriate options. 
148    * This is used to provide the command <code>includegraphics</code>. 
149    */
150   headerGrp {
151     String getFileName() {
152       return "headerGrp.tex";
153     }
154 
155     /**
156      * The comment string which is that of tex. 
157      */
158     String commentStr() {
159       return "%";
160     }
161 
162     // In the long run, the privacy settings are configurable 
163     boolean doFilter() {
164       return true;
165     }
166 
167     boolean hasShebang() {
168       return false;
169     }
170   },
171   /**
172    * A header file used to hide metainfo in a PDF file. 
173    * This is mainly used for security, i.e. privacy reasons, 
174    * but the current header file makes a latex main file 
175    * which has no date in the text reproducible 
176    * at least for lualatex and for pdflatex, but not for xelatex. 
177    * <p>
178    * In the long run, this shall be filtered 
179    * to make the supression configurable. 
180    */
181   headerSuppressMetaPDF {
182     String getFileName() {
183       return "headerSuppressMetaPDF.tex";
184     }
185 
186     /**
187      * The comment string which is that of tex. 
188      */
189     String commentStr() {
190       return "%";
191     }
192 
193     // In the long run, the privacy settings are configurable 
194     boolean doFilter() {
195       return true;
196     }
197 
198     boolean hasShebang() {
199       return false;
200     }
201   },
202   /**
203    * The general header file mostly loading packages. 
204    * Various main files may require additional headers 
205    * but this is currently the minimum, 
206    * so to speak the smallest common multiple. 
207    * It is inspired by pandoc and it is written to work 
208    * for all common latex compiler, 
209    * for direct creation of PDF or for creation of DVI/XDV, 
210    * as a final result or as an intermediate step, 
211    * for document classes including also <code>beamer</code>, 
212    * for package <code>tex4ht</code> and many other variants. 
213    */
214   header {
215     String getFileName() {
216       return "header.tex";
217     }
218 
219     /**
220      * The comment string which is that of tex. 
221      */
222     String commentStr() {
223       return "%";
224     }
225 
226     boolean hasShebang() {
227       return false;
228     }
229   };
230 
231   /**
232    * Returns the filename of the resource. 
233    * It is injected under this file name 
234    * in the folder given by {@link Settings#texSrcDirectory}. 
235    * 
236    * @return
237    *    the filename of the resource. 
238    */
239   abstract String getFileName();
240 
241   /**
242    * Returns the character indicating a comment. 
243    * 
244    * @return
245    *    the character indicating a comment. 
246    *    By default this is <code>#</code> and is overwritten by need. 
247    *    It is appropriate for bash, perl and also as chktexrc. 
248    *    For TEX filtes it must be overwritten. 
249    */
250   String commentStr() {
251     return "#";
252   }
253 
254   /**
255    * Returns whether this file must be filtered before being injected. 
256    * By default this is <code>false</code> and is overwritten by need. 
257    * 
258    * @return
259    *   whether this file must be filtered before being injected. 
260    *   This is <code>false</code>, except for {@link Injection#latexmkrc} 
261    *   for which it is vital 
262    *   and for {@link Injection#headerGrp} and {@link #headerSuppressMetaPDF} 
263    * in view of future configurability. 
264    */
265   boolean doFilter() {
266     return false;
267   }
268 
269   /**
270    * Returns whether the according injection shall be executable. 
271    * By default this is <code>false</code> and is overwritten by need. 
272    * 
273    * @return
274    *    whether the according injection shall be executable. 
275    */
276   boolean setExecutable() {
277     return false;
278   }
279 
280   abstract boolean hasShebang();
281 }