Package eu.simuline.m2latex.core
Class LatexPreProcessor
- java.lang.Object
-
- eu.simuline.m2latex.core.AbstractLatexProcessor
-
- eu.simuline.m2latex.core.LatexPreProcessor
-
public class LatexPreProcessor extends AbstractLatexProcessor
The latex pre-processor is for preprocessing graphic files in formats which cannot be included directly into a latex-file and in finding the latex main files which is done inprocessGraphicsSelectMain(File, DirNode)and in clearing the created files from the latex source directory inclearCreated(File).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classLatexPreProcessor.SuffixHandlerHandler for each suffix of a source file.
-
Field Summary
Fields Modifier and Type Field Description private static StringSUFFIX_BBprivate static StringSUFFIX_BIB(package private) static StringSUFFIX_EPS(package private) static StringSUFFIX_EPSTEXprivate static StringSUFFIX_FIGprivate static StringSUFFIX_GPprivate static StringSUFFIX_JPGprivate static StringSUFFIX_MPprivate static StringSUFFIX_MPSprivate static StringSUFFIX_MPX(package private) static StringSUFFIX_PDFTEXprivate static StringSUFFIX_PNGprivate static StringSUFFIX_PTXprivate static StringSUFFIX_SVGprivate static StringSUFFIX_TEXprivate static StringSUFFIX_XBBprivate static Map<String,LatexPreProcessor.SuffixHandler>SUFFIX2HANDLERMaps the suffix to the according handler.private static StringXFIG_TEX_LANGUAGEThe name of the language used by theSettings.getFig2devCommand()to specify ``special'' text without graphic of an xfig-picture.-
Fields inherited from class eu.simuline.m2latex.core.AbstractLatexProcessor
executor, fileUtils, log, settings, SUFFIX_FLS, SUFFIX_LOG, SUFFIX_PDF, SUFFIX_VOID
-
-
Constructor Summary
Constructors Constructor Description LatexPreProcessor(Settings settings, CommandExecutor executor, LogWrapper log, TexFileUtils fileUtils)
-
Method Summary
Modifier and Type Method Description private voidaddIfLatexMain(File texFile, Collection<File> latexMainFiles)If the tex-filetexFileis a latex main file, add it tolatexMainFiles.private String[]buildArgumentsFig2PdfEps(String language, String optionsGen, String optionsPdfEps, File figFile, File grpFile)Returns an array of options of the form-L <language> <optionsGen> <optionsPdfEps> xxx.fig xxx.pdf/xxx.epsfor invocation ofSettings.getFig2devCommand()for creation of the pdf/eps-part of a fig-figure as done inrunFig2DevInTex(File, LatexDev).private String[]buildArgumentsFig2Ptx(String optionsGen, String optionsPtx, File figFile, File ptxFile)Returns an array of options of the form-L <language> <optionsGen> <optionsPdfEps> -p xxx xxx.fig xxx.ptxfor invocation ofSettings.getFig2devCommand()for creation of the tex-part of a fig-figure as done inrunFig2TexInclDev(File).protected static String[]buildNullArguments(String options, File file)Returns an array of strings, where the 0th entry isnulland a placeholder for option-xor-mwhen used byrunEbb(File)and for the export option when used byrunSvg2Dev(File, LatexDev, boolean)then follow the options fromoptionsand finally comes the name offile.(package private) voidclearCreated(File texDir)Deletes all created files in the directory represented bytexDirtracing subdirectories recursively.private voidclearCreated(File dir, DirNode node)Deletes all created files in the directory represented bynode, recursively.private voidclearTargetJpgPng(File file)Deletes the graphic files created from the svg-filesvgFile.private voidclearTargetMp(File mpFile)Deletes the graphic files created from the metapost-filempFile.private voidclearTargetPtxPdfEps(File grpFile)Deletes the filesxxx.ptx,xxx.pdfandxxx.epscreated from the graphic filegrpFileof the formxxx.y.private voidclearTargetTexIfLatexMain(File texFile)Deletes the files created from the tex-filetexFile, if that is a latex main file.private voiddeleteIfExists(File file, String suffix)Logging: EFU05: Failed to delete fileprivate booleanisLatexMainFile(File texFile)Returns whethertexFileis a latex main file, provided it is readable.(package private) Collection<File>processGraphicsSelectMain(File dir, DirNode node)Detects files in the directory represented bytexNodeand in subdirectories recursively: those which are in various graphic formats incompatible with LaTeX are converted into formats which can be inputted or included directly into a latex file.private voidprocessGraphicsSelectMain(File dir, DirNode node, Collection<String> skipped, Collection<File> latexMainFiles)Logging: WFU03: cannot close file EFU06: Cannot move file WPP02: tex file may be latex main file EEX01, EEX02, EEX03, WEX04, WEX05: if applications for preprocessing graphic files failed.private voidprocessGraphicsSelectMainRec(File dir, DirNode node, Collection<String> skipped, Collection<File> latexMainFiles)LikeprocessGraphicsSelectMainRec(File,DirNode,Collection,Collection)but with recursion to subdirectories.private voidrunEbb(File file)private voidrunFig2Dev(File figFile)Converts the fig-filefigFileinto a tex-file with ending ptx including a pdf-file or an eps-file also created.private voidrunFig2DevInTex(File figFile, LatexDev dev)FromfigFilecreate pdf/eps-file containing graphics without text with special flag set.private voidrunFig2TexInclDev(File figFile)FromfigFilecreate tex-file containing text with special flag set and including a graphic file containing the rest offigFile.private voidrunGnuplot2Dev(File gpFile)Converts a gnuplot-file into a tex-file with ending ptx including a pdf-file or an eps-file also created.private voidrunGnuplot2Dev(File gpFile, LatexDev dev)private voidrunMetapost2mps(File mpFile)Runs mpost on mp-files to generate mps-files.private voidrunSvg2Dev(File svgFile)Converts an svg-file into a tex-file with ending ptx including a pdf-file or an eps-file also created.private voidrunSvg2Dev(File svgFile, LatexDev dev, boolean renameTex)-
Methods inherited from class eu.simuline.m2latex.core.AbstractLatexProcessor
buildArguments, hasErrsWarns, logErrs, logWarn, logWarns, update
-
-
-
-
Field Detail
-
SUFFIX2HANDLER
private static final Map<String,LatexPreProcessor.SuffixHandler> SUFFIX2HANDLER
Maps the suffix to the according handler. If the handler isnull, there is no handler.
-
SUFFIX_TEX
private static final String SUFFIX_TEX
- See Also:
- Constant Field Values
-
SUFFIX_PTX
private static final String SUFFIX_PTX
- See Also:
- Constant Field Values
-
SUFFIX_PDFTEX
static final String SUFFIX_PDFTEX
- See Also:
- Constant Field Values
-
SUFFIX_EPSTEX
static final String SUFFIX_EPSTEX
- See Also:
- Constant Field Values
-
SUFFIX_FIG
private static final String SUFFIX_FIG
- See Also:
- Constant Field Values
-
SUFFIX_SVG
private static final String SUFFIX_SVG
- See Also:
- Constant Field Values
-
SUFFIX_GP
private static final String SUFFIX_GP
- See Also:
- Constant Field Values
-
SUFFIX_MP
private static final String SUFFIX_MP
- See Also:
- Constant Field Values
-
SUFFIX_MPS
private static final String SUFFIX_MPS
- See Also:
- Constant Field Values
-
SUFFIX_MPX
private static final String SUFFIX_MPX
- See Also:
- Constant Field Values
-
SUFFIX_JPG
private static final String SUFFIX_JPG
- See Also:
- Constant Field Values
-
SUFFIX_PNG
private static final String SUFFIX_PNG
- See Also:
- Constant Field Values
-
SUFFIX_BIB
private static final String SUFFIX_BIB
- See Also:
- Constant Field Values
-
SUFFIX_EPS
static final String SUFFIX_EPS
- See Also:
- Constant Field Values
-
SUFFIX_XBB
private static final String SUFFIX_XBB
- See Also:
- Constant Field Values
-
SUFFIX_BB
private static final String SUFFIX_BB
- See Also:
- Constant Field Values
-
XFIG_TEX_LANGUAGE
private static final String XFIG_TEX_LANGUAGE
The name of the language used by theSettings.getFig2devCommand()to specify ``special'' text without graphic of an xfig-picture. Note that the languagespdftex_tandpstex_tare equivalent.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LatexPreProcessor
LatexPreProcessor(Settings settings, CommandExecutor executor, LogWrapper log, TexFileUtils fileUtils)
-
-
Method Detail
-
runFig2Dev
private void runFig2Dev(File figFile) throws BuildFailureException
Converts the fig-filefigFileinto a tex-file with ending ptx including a pdf-file or an eps-file also created. To that end, invokesrunFig2DevInTex(File, LatexDev)twice to create a pdf-file and an eps-file and invokesrunFig2TexInclDev(File)(once) to create the tex-file.Logging:
- EEX01, EEX02, EEX03, WEX04, WEX05: if running the fig2dev command failed.
- Parameters:
figFile- the fig file to be processed.- Throws:
BuildFailureException- TEX01 if invocation of the fig2dev command returned bySettings.getFig2devCommand()failed. This is invoked twice: once for creating the pdf-file and once for creating the pdf_t-file.- See Also:
processGraphicsSelectMain(File, DirNode)
-
runFig2DevInTex
private void runFig2DevInTex(File figFile, LatexDev dev) throws BuildFailureException
FromfigFilecreate pdf/eps-file containing graphics without text with special flag set. The output format depends ondev. The resulting file is included in some tex-file created byrunFig2TexInclDev(File). Conversion is done bySettings.getFig2devCommand().Logging: FIXME: EEX01, EEX02, EEX03, WEX04, WEX05
- Parameters:
figFile- the fig-file to be processeddev- represents the target: either a pdf-file or an eps-file.- Throws:
BuildFailureException- FIXME: TEX01,
-
buildArgumentsFig2PdfEps
private String[] buildArgumentsFig2PdfEps(String language, String optionsGen, String optionsPdfEps, File figFile, File grpFile)
Returns an array of options of the form-L <language> <optionsGen> <optionsPdfEps> xxx.fig xxx.pdf/xxx.epsfor invocation ofSettings.getFig2devCommand()for creation of the pdf/eps-part of a fig-figure as done inrunFig2DevInTex(File, LatexDev).- Parameters:
language- is the output language which is eitherpdftexorpstexoptionsGen- the general options, applying to both the pdf/eps part and the tex part of the figure under consideration.optionsPdfEps- the options, specific for the pdf/eps part (which is the same) of the figure under consideration.figFile- the fig-file to be transformed.grpFile- the graphics file (pdf/eps-file) which is the result of the transformation.
-
runFig2TexInclDev
private void runFig2TexInclDev(File figFile) throws BuildFailureException
FromfigFilecreate tex-file containing text with special flag set and including a graphic file containing the rest offigFile. Inclusion is without file extension and so both possible results ofrunFig2DevInTex(File, LatexDev)can be included when compiling with latex. Conversion is done bySettings.getFig2devCommand().Logging: FIXME: warning EEX01, EEX02, EEX03, WEX04, WEX05
- Parameters:
figFile- the fig-file to be processed- Throws:
BuildFailureException- FIXME: TEX01,
-
buildArgumentsFig2Ptx
private String[] buildArgumentsFig2Ptx(String optionsGen, String optionsPtx, File figFile, File ptxFile)
Returns an array of options of the form-L <language> <optionsGen> <optionsPdfEps> -p xxx xxx.fig xxx.ptxfor invocation ofSettings.getFig2devCommand()for creation of the tex-part of a fig-figure as done inrunFig2TexInclDev(File). Note that the option-p xxxspecifies the name of the pdf/eps-file included in the result fileptxFilewithout suffix.- Parameters:
optionsGen- the general options, applying to both the pdf/eps part and the tex part of the figure under consideration.optionsPtx- the options, specific for the tex part of the figure under consideration (for the ptx-file).figFile- the fig-file to be transformed.ptxFile- the ptx-file which is the result of the transformation.
-
clearTargetPtxPdfEps
private void clearTargetPtxPdfEps(File grpFile)
Deletes the filesxxx.ptx,xxx.pdfandxxx.epscreated from the graphic filegrpFileof the formxxx.y.Logging: EFU05: Failed to delete file
- Parameters:
grpFile- a graphic file.
-
runGnuplot2Dev
private void runGnuplot2Dev(File gpFile) throws BuildFailureException
Converts a gnuplot-file into a tex-file with ending ptx including a pdf-file or an eps-file also created. To that end, invokesrunGnuplot2Dev(File, LatexDev)twice to create a pdf-file and an eps-file and to create the tex-file which can include both.Logging:
- EEX01, EEX02, EEX03, WEX04, WEX05: if running the ptx/pdf-conversion built-in in gnuplot fails.
- Parameters:
gpFile- the gp-file (gnuplot format) to be converted to pdf and ptx.- Throws:
BuildFailureException- TEX01 if invocation of the ptx/pdf-conversion built-in in gnuplot fails.- See Also:
processGraphicsSelectMain(File, DirNode)
-
runGnuplot2Dev
private void runGnuplot2Dev(File gpFile, LatexDev dev) throws BuildFailureException
- Throws:
BuildFailureException
-
runMetapost2mps
private void runMetapost2mps(File mpFile) throws BuildFailureException
Runs mpost on mp-files to generate mps-files.Logging:
- WFU03: cannot close log file
- EAP01: Running
commandfailed. For details... - EAP02: Running
commandfailed. No log file - WAP04: if log file is not readable.
- EEX01, EEX02, EEX03, WEX04, WEX05: if running the mpost command failed.
- Parameters:
mpFile- the metapost file to be processed.- Throws:
BuildFailureException- TEX01 if invocation of the mpost command failed.- See Also:
processGraphicsSelectMain(File, DirNode)
-
clearTargetMp
private void clearTargetMp(File mpFile)
Deletes the graphic files created from the metapost-filempFile.Logging:
- WFU01: Cannot read directory ...
- EFU05: Failed to delete file
- Parameters:
mpFile- a metapost file.
-
runSvg2Dev
private void runSvg2Dev(File svgFile) throws BuildFailureException
Converts an svg-file into a tex-file with ending ptx including a pdf-file or an eps-file also created. To that end, invokesrunSvg2Dev(File, LatexDev, boolean)twice to create a pdf-file and an eps-file and to create the tex-file which can include both.Logging:
- EEX01, EEX02, EEX03, WEX04, WEX05: if running the ptx/pdf-conversion built-in in svg2dev fails.
- EFU06 if moving a file fails.
- Parameters:
svgFile- the svg-file to be converted to a pdf-file and a ptx-file.- Throws:
BuildFailureException- TEX01 if invocation of the ptx/pdf-conversion built-in in svg2dev fails.- See Also:
processGraphicsSelectMain(File, DirNode)
-
runSvg2Dev
private void runSvg2Dev(File svgFile, LatexDev dev, boolean renameTex) throws BuildFailureException
- Throws:
BuildFailureException
-
runEbb
private void runEbb(File file) throws BuildFailureException
- Throws:
BuildFailureException
-
buildNullArguments
protected static String[] buildNullArguments(String options, File file)
Returns an array of strings, where the 0th entry isnulland a placeholder for option-xor-mwhen used byrunEbb(File)and for the export option when used byrunSvg2Dev(File, LatexDev, boolean)then follow the options fromoptionsand finally comes the name offile.
-
clearTargetJpgPng
private void clearTargetJpgPng(File file)
Deletes the graphic files created from the svg-filesvgFile.Logging: EFU05: Failed to delete file
-
deleteIfExists
private void deleteIfExists(File file, String suffix)
Logging: EFU05: Failed to delete file
-
isLatexMainFile
private boolean isLatexMainFile(File texFile)
Returns whethertexFileis a latex main file, provided it is readable. Otherwise logs a warning and returnsfalse.Logging:
- WFU03: cannot close
- WPP02: tex file may be latex main file
- Parameters:
texFile- the tex-file to decide on whether it is a latex main file.- Returns:
- whether
texFileis definitively a latex main file. If this is not readable,false.
-
addIfLatexMain
private void addIfLatexMain(File texFile, Collection<File> latexMainFiles)
If the tex-filetexFileis a latex main file, add it tolatexMainFiles.Logging:
- WFU03: cannot close
- WPP02: tex file may be latex main file
- Parameters:
texFile- the tex-file to be added tolatexMainFilesif it is a latex main file.latexMainFiles- the collection of latex main files found so far.
-
clearTargetTexIfLatexMain
private void clearTargetTexIfLatexMain(File texFile)
Deletes the files created from the tex-filetexFile, if that is a latex main file.Logging:
- WPP02: tex file may be latex main file
- WFU01: Cannot read directory...
- WFU03: cannot close tex file
- EFU05: Failed to delete file
- Parameters:
texFile- the tex-file of which the created files shall be deleted if it is a latex main file.
-
processGraphicsSelectMain
Collection<File> processGraphicsSelectMain(File dir, DirNode node) throws BuildFailureException
Detects files in the directory represented bytexNodeand in subdirectories recursively:- those which are in various graphic formats incompatible with LaTeX are converted into formats which can be inputted or included directly into a latex file.
- returns the set of latex main files.
Logging:
- WFU03: cannot close
- WPP02: tex file may be latex main file
- WPP03: Skipped processing of files with suffixes ...
- EEX01, EEX02, EEX03, WEX04, WEX05: if running graphic processors failed.
- EFU06: if moving a file fails.
- Parameters:
dir- represents the tex source directory or a subdirectory.node- a node associated withdir.- Returns:
- the collection of latex main files.
- Throws:
BuildFailureException- TEX01 invokingprocessGraphicsSelectMain(File, DirNode, Collection, Collection)
-
processGraphicsSelectMain
private void processGraphicsSelectMain(File dir, DirNode node, Collection<String> skipped, Collection<File> latexMainFiles) throws BuildFailureException
Logging:
- WFU03: cannot close file
- EFU06: Cannot move file
- WPP02: tex file may be latex main file
- EEX01, EEX02, EEX03, WEX04, WEX05: if applications for preprocessing graphic files failed.
- Parameters:
dir- represents the tex source directory or a subdirectory.node- a node associated withdir.skipped- the collection of suffixes of files with handling skipped so far because there is no handler. FIXME: interesting for files without suffix or for hidden files.latexMainFiles- the collection of latex main files found so far.- Throws:
BuildFailureException- TEX01 invokingLatexPreProcessor.SuffixHandler.procSrc(File, LatexPreProcessor)only forLatexPreProcessor.SuffixHandler.fig,LatexPreProcessor.SuffixHandler.gpandLatexPreProcessor.SuffixHandler.mpbecause these invoke external programs.
-
processGraphicsSelectMainRec
private void processGraphicsSelectMainRec(File dir, DirNode node, Collection<String> skipped, Collection<File> latexMainFiles) throws BuildFailureException
LikeprocessGraphicsSelectMainRec(File,DirNode,Collection,Collection)but with recursion to subdirectories.- Throws:
BuildFailureException
-
clearCreated
void clearCreated(File texDir)
Deletes all created files in the directory represented bytexDirtracing subdirectories recursively. For details of deletions within a single directory seeclearCreated(File, DirNode).Logging:
- WPP02: tex file may be latex main file
- WFU01: Cannot read directory...
- WFU03: cannot close tex file
- EFU05: Failed to delete file
- Parameters:
texDir- represents the tex source directory or a subdirectory.
-
clearCreated
private void clearCreated(File dir, DirNode node)
Deletes all created files in the directory represented bynode, recursively. In each directory, the sub-directories are not deleted themselves but cleaned recursively. The other files are cleaned, i.e. their targets are deleted in an ordering reverse to creation proceeding in the following steps:-
First the targets of the latex main files are deleted,
whereas the targets of the graphic (source) files
are just scheduled for deletion.
For details see
LatexPreProcessor.SuffixHandler.clearTarget(File, LatexPreProcessor, Map). FIXME: what about deletion of a graphic source file in this course? - Then the graphic source files scheduled are un-scheduled if deleted by some latex main file.
- Finally, the targets of the graphic souce files are deleted. FIXME: what if this results in deletion of a graphic source file?
LatexPreProcessor.SuffixHandler.getSuffix()) it is ignored. Else its target is cleared as described inLatexPreProcessor.SuffixHandler.clearTarget(File, LatexPreProcessor, Map).Logging:
- WPP02: tex file may be latex main file
- WFU01: Cannot read directory...
- WFU03: cannot close tex file
- EFU05: Failed to delete file
- Parameters:
dir- represents the tex source directory or a subdirectory.node- a node associated withdir.
-
First the targets of the latex main files are deleted,
whereas the targets of the graphic (source) files
are just scheduled for deletion.
For details see
-
-