From 50e7442d35b91a7d48d587814a6d0e92df796e60 Mon Sep 17 00:00:00 2001 From: stfm Date: Mon, 25 Jun 2012 22:39:49 +0200 Subject: [PATCH] appendix implementation enabled + fixed --- .../stfm/texdoclet/HTMLtoLaTeXBackEnd.java | 73 ++++++++++++------- .../java/org/stfm/texdoclet/TeXDoclet.java | 37 +++++----- .../stfm/texdoclet/doc-files/appendix_a.html | 2 + .../stfm/texdoclet/doc-files/appendix_b.txt | 1 + 4 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/stfm/texdoclet/doc-files/appendix_a.html create mode 100644 src/main/java/org/stfm/texdoclet/doc-files/appendix_b.txt diff --git a/src/main/java/org/stfm/texdoclet/HTMLtoLaTeXBackEnd.java b/src/main/java/org/stfm/texdoclet/HTMLtoLaTeXBackEnd.java index 6445132..b2fa34d 100755 --- a/src/main/java/org/stfm/texdoclet/HTMLtoLaTeXBackEnd.java +++ b/src/main/java/org/stfm/texdoclet/HTMLtoLaTeXBackEnd.java @@ -24,9 +24,16 @@ import javax.swing.text.html.parser.ParserDelegator; import com.keypoint.PngEncoder; /** + *

* This class implements a ParserCallback that translates HTML to * the corresponding LaTeX. Not all tags a processed * but the most common are. + *

+ * HTML links to files located in the doc-files directory (appendix_a.html, appendix_b.txt) are transformed to + * references to the appendix, whereby the referenced files itself are included + * in the appendix. * * @see javax.swing.text.html.parser.ParserDelegator * @author Soeren Caspersen @@ -250,35 +257,37 @@ public class HTMLtoLaTeXBackEnd extends HTMLEditorKit.ParserCallback { doPrintURL = (String) attrSet.getAttribute("doprinturl"); if (refurl != null) { if (TeXDoclet.hyperref) { - // if (refurl.toLowerCase().startsWith("doc-files")) { - // File file = new File(TeXDoclet.packageDir, refurl); - // if (file.exists()) { - // if (TeXDoclet.appendencies.contains(file.getPath())) { - // refurl = (String) TeXDoclet.appendencies - // .get(file.getPath()); - // } else { - // refurl = "appendix" - // + new Integer( - // TeXDoclet.appendencies.size() + 1); - // TeXDoclet.appendencies.put(file.getPath(), - // refurl); - // } - // ret.append("\\hyperref{}{" + refurl + "}{}{"); - // return; - // } - // } - - String sharp = ""; - if (refurl.indexOf("#") >= 0) { - sharp = refurl.substring(refurl.indexOf("#") + 1, - refurl.length()); - if (sharp.indexOf("%") >= 0) { - sharp = ""; // Don't know what to do with '%' + if (refurl.toLowerCase().startsWith("doc-files")) { + File file = new File(TeXDoclet.packageDir, refurl); + if (file.exists()) { + if (TeXDoclet.appendencies.contains(file.getPath())) { + refurl = (String) TeXDoclet.appendencies + .get(file.getPath()); + } else { + refurl = "appendix" + + new Integer( + TeXDoclet.appendencies.size() + 1); + TeXDoclet.appendencies.put(file.getPath(), + refurl); + } + ret.append("{"); + return; } - refurl = refurl.substring(0, refurl.indexOf("#")); + } else { + + String sharp = ""; + if (refurl.indexOf("#") >= 0) { + sharp = refurl.substring(refurl.indexOf("#") + 1, + refurl.length()); + if (sharp.indexOf("%") >= 0) { + sharp = ""; // Don't know what to do with '%' + } + refurl = refurl.substring(0, refurl.indexOf("#")); + } + ret.append("\\hyperref{" + refurl + "}{" + sharp + + "}{}{"); + // ret.append("\\href{" + refurl + "}{"); } - ret.append("\\hyperref{" + refurl + "}{" + sharp + "}{}{"); - // ret.append("\\href{" + refurl + "}{"); } else { ret.append("{\\bf "); } @@ -392,6 +401,15 @@ public class HTMLtoLaTeXBackEnd extends HTMLEditorKit.ParserCallback { ret.append("}"); } else if (tag == HTML.Tag.A) { if (refurl != null) { + + if (refurl.startsWith("appendix")) { + + ret.append("\\refdefined{" + refurl + "}"); + ret.append("}"); + + return; + + } ret.append("}"); if (doPrintURL != null) { if (!refurl.equals("")) { @@ -400,6 +418,7 @@ public class HTMLtoLaTeXBackEnd extends HTMLEditorKit.ParserCallback { ret.append(")"); } } + } else if (refname != null) { ret.append("}"); } diff --git a/src/main/java/org/stfm/texdoclet/TeXDoclet.java b/src/main/java/org/stfm/texdoclet/TeXDoclet.java index 04fe5fc..573b84a 100755 --- a/src/main/java/org/stfm/texdoclet/TeXDoclet.java +++ b/src/main/java/org/stfm/texdoclet/TeXDoclet.java @@ -213,7 +213,8 @@ public class TeXDoclet extends Doclet { System.out.println("command to execute : " + "javadoc " + argsString); - // TODO something goes wrong here. javadoc always prints help output + // TODO something goes wrong here. javadoc always prints help + // output. Process p = Runtime.getRuntime().exec("javadoc", argsJd); p.waitFor(); @@ -675,23 +676,25 @@ public class TeXDoclet extends Doclet { os.println("}"); } - // if (appendencies.size() > 0) { - // os.println("\\appendix"); - // Iterator it = appendencies.keySet().iterator(); - // while (it.hasNext()) { - // os.println(" \\chapter{" + (char) ('A' + 1) - // + "}\n\\hyperdef{appendix1}{}"); - // os.println(" \\hyperdef{appendix1}{}sdafafdasd"); - // String sfa = (String) it.next(); - // System.out.println(sfa); - // addFile(os, sfa, true); - // } - // } + if (appendencies.size() > 0) { + os.println("\\appendix"); + Iterator it = appendencies.keySet().iterator(); + int i = 0; + while (it.hasNext()) { + os.println("\\" + sectionLevels[0] + "{}{"); + os.println(" \\label{appendix" + (i + 1) + "}"); + String sfa = (String) it.next(); + // System.out.println(sfa); + addFile(os, sfa, true); + os.println("}"); + i++; + } + } - // os.println("\\markboth{}{}"); - // if (index) { - // os.println("\\printindex"); - // } + os.println("\\markboth{}{}"); + if (index) { + os.println("\\printindex"); + } addFile(os, finishFile, false); diff --git a/src/main/java/org/stfm/texdoclet/doc-files/appendix_a.html b/src/main/java/org/stfm/texdoclet/doc-files/appendix_a.html new file mode 100644 index 0000000..bfe054d --- /dev/null +++ b/src/main/java/org/stfm/texdoclet/doc-files/appendix_a.html @@ -0,0 +1,2 @@ +

Appendix A content

+content of file doc-files/appendix_a.html \ No newline at end of file diff --git a/src/main/java/org/stfm/texdoclet/doc-files/appendix_b.txt b/src/main/java/org/stfm/texdoclet/doc-files/appendix_b.txt new file mode 100644 index 0000000..a7bbb87 --- /dev/null +++ b/src/main/java/org/stfm/texdoclet/doc-files/appendix_b.txt @@ -0,0 +1 @@ +content of file doc-files/appendix_b.txt \ No newline at end of file