diff --git a/src/main/java/org/stfm/texdoclet/HelpOutput.java b/src/main/java/org/stfm/texdoclet/HelpOutput.java
index a26040d..9036732 100644
--- a/src/main/java/org/stfm/texdoclet/HelpOutput.java
+++ b/src/main/java/org/stfm/texdoclet/HelpOutput.java
@@ -3,18 +3,18 @@ package org.stfm.texdoclet;
public class HelpOutput {
protected static void printHelp() {
+ try {
+ throw new Exception("");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
System.err.println("TeXDoclet Usage:");
System.err
.println("-title
A title to use for the generated output document.");
System.err
- .println("-subtitle A subtitle for the output document.");
+ .println("-subtitle A subtitle for the output document. No -title will result in no title page.");
System.err
- .println(" No -title will result in no title page.");
- System.err
- .println("-output Specifies the output file to write to. If none");
- System.err
- .println(" specified, the default is docs.tex in the current");
- System.err.println(" directory.");
+ .println("-output Specifies the output file to write to. Default is docs.tex in the current directory.");
System.err
.println("-docclass LaTeX2e document class, `report' is the default.");
System.err
@@ -66,10 +66,11 @@ public class HelpOutput {
System.err
.println("-sectionlevel Specifies the highest level of sections (either \"subsection\", \"section\" or \"chapter\").");
System.err
- .println("-imagespath Path to the texdoclet_images dir (absolute or relative to the output document .tex file).");
+ .println("-imagespath Path to 'texdoclet_images' dir that is created by TeXDoclet to hold referenced images (absolute or relative to the output document .tex file).");
System.err
.println("-tablescale Scale factor to specify width of tables. Default value is 0.9.");
-
+ System.err
+ .println("-createpdf Calles pdflatex to create a .pdf fiele from the .tex output file.");
}
}
diff --git a/src/main/java/org/stfm/texdoclet/TeXDoclet.java b/src/main/java/org/stfm/texdoclet/TeXDoclet.java
index ed5e087..acc2a46 100755
--- a/src/main/java/org/stfm/texdoclet/TeXDoclet.java
+++ b/src/main/java/org/stfm/texdoclet/TeXDoclet.java
@@ -36,6 +36,7 @@ import com.sun.javadoc.SeeTag;
import com.sun.javadoc.Tag;
import com.sun.javadoc.ThrowsTag;
import com.sun.javadoc.Type;
+import com.sun.tools.doclets.standard.Standard;
/**
* This class provides a Java javadoc Doclet which generates a option is a
- * recognized option.
+ * Doclet class method that returns how many arguments would be consumed if
+ * option is a recognized option.
*
* @param option
* the option to check
@@ -374,13 +359,18 @@ public class TeXDoclet extends Doclet {
return 2;
} else if (option.equals("-tablescale")) {
return 2;
+ } else if (option.equals("-createpdf")) {
+ return 1;
}
- System.out.println("unknown option " + option);
+ System.out.println("unknown TeXDoclet option " + option);
+
+ // return Standard.optionLength(option);
return Doclet.optionLength(option);
}
/**
- * Checks the passed options and their arguments for validity.
+ * Doclet class method that checks the passed options and their arguments
+ * for validity.
*
* @param args
* the arguments to check
@@ -473,6 +463,8 @@ public class TeXDoclet extends Doclet {
introFile = args[i][1];
} else if (args[i][0].equals("-tablescale")) {
tableWidthScale = Double.parseDouble(args[i][1]);
+ } else if (args[i][0].equals("-createpdf")) {
+ createPdf = true;
}
if (sectionLevelMax != null
@@ -486,90 +478,16 @@ public class TeXDoclet extends Doclet {
}
System.out.println("args parsed");
- return true;
- }
- public static void init() {
-
- map2 = new Hashtable();
- map = new Vector();
- try {
- os = new PrintWriter(new FileWriter(outfile));
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- try {
- if (includeTexOutputInOtherTexFile) {
- outfilePreamble = outfile
- .substring(0, outfile.lastIndexOf("."))
- + OUT_PREAMBLE_SUFFIX + ".tex";
- osPreamble = new PrintWriter(new FileWriter(outfilePreamble));
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- initSections();
- }
-
- public static void initSections() {
- if (sectionLevelMax == null) {
- if (!includeTexOutputInOtherTexFile) {
- if (docclass.equals("scrreprt") || docclass.equals("report")) {
- sectionLevelMax = CHAPTER_LEVEL;
- } else if (docclass.equals("scrartcl")
- || docclass.equals("article")) {
- sectionLevelMax = SECTION_LEVEL;
- } else {
- sectionLevelMax = SECTION_LEVEL;
- }
- } else {
- sectionLevelMax = SECTION_LEVEL;
- }
- }
-
- if (sectionLevelMax.equals(CHAPTER_LEVEL)) {
- sectionLevels[0] = "chapter";
- sectionLevels[1] = "section";
- sectionLevels[2] = "subsection";
- } else if (sectionLevelMax.equals(SECTION_LEVEL)) {
- sectionLevels[0] = "section";
- sectionLevels[1] = "subsection";
- sectionLevels[2] = "subsubsection";
- } else if (sectionLevelMax.equals(SUBSECTION_LEVEL)) {
- sectionLevels[0] = "subsection";
- sectionLevels[1] = "subsubsection";
- sectionLevels[2] = "subsubsection";
- }
- }
-
- public static void finish() {
- if (os != null) {
- try {
- os.close();
- } catch (Exception ex) {
- }
- }
- if (osPreamble != null) {
- try {
- osPreamble.close();
- } catch (Exception ex) {
- }
- }
- try {
- FileOutputStream ostream = new FileOutputStream(outfile + ".map");
- ObjectOutputStream p = new ObjectOutputStream(ostream);
- p.writeObject(refs);
- p.flush();
- ostream.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ // return Standard.validOptions(args, err);
+ return Doclet.validOptions(args, err);
}
/**
- * Called by the framework to format the entire document
+ * Doclet class method that is called by the framework to format the entire
+ * document
+ *
+ * @Override
*
* @param root
* the root of the starting document
@@ -789,6 +707,61 @@ public class TeXDoclet extends Doclet {
return true;
}
+ static void init() {
+
+ map2 = new Hashtable();
+ map = new Vector();
+ try {
+ os = new PrintWriter(new FileWriter(outfile));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ try {
+ if (includeTexOutputInOtherTexFile) {
+ outfilePreamble = outfile
+ .substring(0, outfile.lastIndexOf("."))
+ + OUT_PREAMBLE_SUFFIX + ".tex";
+ osPreamble = new PrintWriter(new FileWriter(outfilePreamble));
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ initSections();
+ }
+
+ static void initSections() {
+ if (sectionLevelMax == null) {
+ if (!includeTexOutputInOtherTexFile) {
+ if (docclass.equals("scrreprt") || docclass.equals("report")) {
+ sectionLevelMax = CHAPTER_LEVEL;
+ } else if (docclass.equals("scrartcl")
+ || docclass.equals("article")) {
+ sectionLevelMax = SECTION_LEVEL;
+ } else {
+ sectionLevelMax = SECTION_LEVEL;
+ }
+ } else {
+ sectionLevelMax = SECTION_LEVEL;
+ }
+ }
+
+ if (sectionLevelMax.equals(CHAPTER_LEVEL)) {
+ sectionLevels[0] = "chapter";
+ sectionLevels[1] = "section";
+ sectionLevels[2] = "subsection";
+ } else if (sectionLevelMax.equals(SECTION_LEVEL)) {
+ sectionLevels[0] = "section";
+ sectionLevels[1] = "subsection";
+ sectionLevels[2] = "subsubsection";
+ } else if (sectionLevelMax.equals(SUBSECTION_LEVEL)) {
+ sectionLevels[0] = "subsection";
+ sectionLevels[1] = "subsubsection";
+ sectionLevels[2] = "subsubsection";
+ }
+ }
+
static void printPreamble(PrintWriter os) {
// this is not our job if including in other document
@@ -2185,4 +2158,83 @@ public class TeXDoclet extends Doclet {
return null;
}
+
+ static void finish() {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (Exception ex) {
+ }
+ }
+ if (osPreamble != null) {
+ try {
+ osPreamble.close();
+ } catch (Exception ex) {
+ }
+ }
+ try {
+
+ FileOutputStream ostream = new FileOutputStream(outfile + ".map");
+ ObjectOutputStream p = new ObjectOutputStream(ostream);
+ p.writeObject(refs);
+ p.flush();
+ ostream.close();
+
+ if (createPdf) {
+ createPdf();
+ }
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ static void createPdf() throws IOException, InterruptedException {
+
+ String cmd = PDFLATEX_CMD + outfile;
+
+ // debuggin only
+ // execute("pwd", null);
+
+ for (int i = 0; i < PDFLATEX_ITERATIONS; i++) {
+ execute(cmd, null, false);
+ }
+
+ }
+
+ static int execute(String cmd, String args[], boolean doOutput)
+ throws IOException, InterruptedException {
+
+ // some logging output :
+ String argsString = "";
+ if (args != null) {
+ argsString = Arrays.toString(args);
+ }
+ System.out.println("command to execute : " + cmd + " " + argsString);
+
+ Process p;
+ if (args == null) {
+ p = Runtime.getRuntime().exec(cmd);
+ } else {
+ p = Runtime.getRuntime().exec(cmd, args);
+ }
+
+ // (?!?) if not reading p.getInputStream() stream, the process execution
+ // seems to be endless and will never return for pdflatex command !
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ p.getInputStream()));
+ String line = reader.readLine();
+ while (line != null) {
+ if (doOutput) {
+ System.out.println("> " + line);
+ }
+ line = reader.readLine();
+ }
+
+ int res = -1;
+ res = p.waitFor();
+
+ System.out.println("return code : " + res);
+ return res;
+ }
}
\ No newline at end of file