From f7464fdd2e33e5dc6c159a4adc8f53902e6d4511 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 13 Apr 2011 23:20:15 -0400 Subject: Initial commit of Luke Shumaker's "dot-files". --- .../contrib/scripts/staticmathjax/.gitignore | 1 + .../contrib/scripts/staticmathjax/README.org | 79 ++++++++ .../contrib/scripts/staticmathjax/README.txt | 91 ++++++++++ .../contrib/scripts/staticmathjax/application.ini | 11 ++ .../scripts/staticmathjax/chrome/chrome.manifest | 1 + .../scripts/staticmathjax/chrome/content/main.js | 198 +++++++++++++++++++++ .../scripts/staticmathjax/chrome/content/main.xul | 11 ++ .../staticmathjax/defaults/preferences/prefs.js | 1 + 8 files changed, 393 insertions(+) create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/.gitignore create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/README.org create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/README.txt create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/application.ini create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/chrome.manifest create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/content/main.js create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/content/main.xul create mode 100644 .emacs.d/org-7.4/contrib/scripts/staticmathjax/defaults/preferences/prefs.js (limited to '.emacs.d/org-7.4/contrib/scripts/staticmathjax') diff --git a/.emacs.d/org-7.4/contrib/scripts/staticmathjax/.gitignore b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/.emacs.d/org-7.4/contrib/scripts/staticmathjax/README.org b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/README.org new file mode 100644 index 0000000..d28fc90 --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/README.org @@ -0,0 +1,79 @@ +Static MathJax v0.1 README +#+AUTHOR: Jan Böcker + +Static MathJax is a XULRunner application which loads a HTML input +file that uses MathJax into a browser, waits until MathJax is done +processing, and then writes the formatted result to an output HTML +file. + +I have only tested exports from Emacs Org-mode as input files. (As of +2010-08-14, MathJax is used by default with HTML exports in the +current Org development version.) + +Optionally, references to the math fonts used will be converted to +"data:" URIs, thus embedding the font data into the HTML file itself. +(see [[http://en.wikipedia.org/wiki/Data_URI_scheme]]) + +The code is licensed under the GNU General Public License version +2, or, at your option, any later version. + + +* Usage + To run Static MathJax, an existing XULRunner installation is + required. From the directory to which you unpacked Static MathJax, + run: + + xulrunner application.ini <--embed-fonts | --final-mathjax-url > + + + If you prefer to call "staticmathjax" instead of "xulrunner + application.ini", link xulrunner-stub into the directory: + ln /usr/lib/xulrunner-1.9.2.8/xulrunner-stub ./staticmathjax + + - input file :: + name of the input file (the result of a HTML export + from Org-mode). It is assumed that this file uses the + UTF-8 character encoding. + + - output file :: + name of the output file. + + - --embed-fonts :: + if specified, the math fonts will be embedded into + the output file using data: URIs + + - --final-mathjax-url :: + if --embed-fonts is not specified, this + must be the URL to a MathJax installation folder (e.g. "MathJax" + if MathJax is installed in a subdirectory, or + "http://orgmode.org/mathjax" to use the version hosted on the Org + website. + + All references to math fonts in the output file will point to + this directory. + +* Caveats + + The input file must not use a MathJax installation on the + web. Otherwise, due to a security feature of Firefox, MathJax will + fallback to image fonts. If you have unpacked MathJax to a + subdirectory "MathJax", specify the following in your Org file: + + #+MathJax: path:"MathJax" + + The math is rendered in Firefox, so MathJax applies its + Firefox-specific settings. When viewing the output files in other + browsers, it will look slightly different than the result that + running MathJax in that browser would produce. + + Internet Explorer does not use the correct font, because it only + supports the EOT font format. For all other browsers (including + Firefox), MathJax uses the OTF font format. + + Embedding fonts into the HTML file wastes some space due to the + base64 encoding used in data: URIs. + + I have found no way to access stdout or set an exit code in an + XULRunner app, so any code which calls Static MathJax has no idea if + processing was successful and when an error occurs, graphical + message boxes are displayed. diff --git a/.emacs.d/org-7.4/contrib/scripts/staticmathjax/README.txt b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/README.txt new file mode 100644 index 0000000..cbcaea1 --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/README.txt @@ -0,0 +1,91 @@ + Static MathJax v0.1 README + ========================== + +Author: Jan Böcker +Date: 2010-08-15 13:53:39 CEST + + +Static MathJax is a XULRunner application which loads a HTML input +file that uses MathJax into a browser, waits until MathJax is done +processing, and then writes the formatted result to an output HTML +file. + +I have only tested exports from Emacs Org-mode as input files. (As of +2010-08-14, MathJax is used by default with HTML exports in the +current Org development version.) + +Optionally, references to the math fonts used will be converted to +"data:" URIs, thus embedding the font data into the HTML file itself. +(see [http://en.wikipedia.org/wiki/Data_URI_scheme]) + +The code is licensed under the GNU General Public License version +2, or, at your option, any later version. + + +Table of Contents +================= +1 Usage +2 Caveats + + +1 Usage +~~~~~~~~ + To run Static MathJax, an existing XULRunner installation is + required. From the directory to which you unpacked Static MathJax, + run: + + xulrunner application.ini <--embed-fonts | --final-mathjax-url > + + + If you prefer to call "staticmathjax" instead of "xulrunner + application.ini", link xulrunner-stub into the directory: + ln /usr/lib/xulrunner-1.9.2.8/xulrunner-stub ./staticmathjax + + input file: + name of the input file (the result of a HTML export + from Org-mode). It is assumed that this file uses the + UTF-8 character encoding. + + output file: + name of the output file. + + --embed-fonts: + if specified, the math fonts will be embedded into + the output file using data: URIs + + --final-mathjax-url : + if --embed-fonts is not specified, this + must be the URL to a MathJax installation folder (e.g. "MathJax" + if MathJax is installed in a subdirectory, or + "[http://orgmode.org/mathjax]" to use the version hosted on the Org + website. + + All references to math fonts in the output file will point to + this directory. + +2 Caveats +~~~~~~~~~~ + + The input file must not use a MathJax installation on the + web. Otherwise, due to a security feature of Firefox, MathJax will + fallback to image fonts. If you have unpacked MathJax to a + subdirectory "MathJax", specify the following in your Org file: + + #+MathJax: path:"MathJax" + + The math is rendered in Firefox, so MathJax applies its + Firefox-specific settings. When viewing the output files in other + browsers, it will look slightly different than the result that + running MathJax in that browser would produce. + + Internet Explorer does not use the correct font, because it only + supports the EOT font format. For all other browsers (including + Firefox), MathJax uses the OTF font format. + + Embedding fonts into the HTML file wastes some space due to the + base64 encoding used in data: URIs. + + I have found no way to access stdout or set an exit code in an + XULRunner app, so any code which calls Static MathJax has no idea if + processing was successful and when an error occurs, graphical + message boxes are displayed. diff --git a/.emacs.d/org-7.4/contrib/scripts/staticmathjax/application.ini b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/application.ini new file mode 100644 index 0000000..d7957b0 --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/application.ini @@ -0,0 +1,11 @@ +[App] +Vendor=Jan Boecker +Name=StaticMathJax +Version=0.2 +BuildID=2 +Copyright=Copyright (c) 2010 Jan Boecker +ID=xulapp@jboecker.de + +[Gecko] +MinVersion=1.8 + diff --git a/.emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/chrome.manifest b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/chrome.manifest new file mode 100644 index 0000000..a05d8c8 --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/chrome.manifest @@ -0,0 +1 @@ +content staticmathjax file:content/ diff --git a/.emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/content/main.js b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/content/main.js new file mode 100644 index 0000000..2e71f3b --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/staticmathjax/chrome/content/main.js @@ -0,0 +1,198 @@ +var docFrame; +var logtextbox; +var destFile; +var embedFonts = false; +var finalMathJaxURL = null; + +function log(text) +{ + logtextbox.setAttribute("value", logtextbox.getAttribute("value") + "\n" + text); +} + +function init() +{ + try { + docFrame = document.getElementById("docFrame"); + logtextbox = document.getElementById("logtextbox"); + + // parse command line arguments + var cmdLine = window.arguments[0]; + cmdLine = cmdLine.QueryInterface(Components.interfaces.nsICommandLine); + + embedFonts = cmdLine.handleFlag("embed-fonts", false); + finalMathJaxURL = cmdLine.handleFlagWithParam("final-mathjax-url", false); + + if (!embedFonts && !finalMathJaxURL) { + alert("You must eiher specify --embed-fonts or --final-mathjax-url"); + window.close(); + return; + } + + sourceFilePath = cmdLine.getArgument(0); + destFilePath = cmdLine.getArgument(1); + if ( !sourceFilePath || !destFilePath ) { + alert("Not enough parameters, expecting two arguments:\nInput file, output file"); + window.close(); + return; + } + + sourceFile = cmdLine.resolveFile(sourceFilePath); + if (! (sourceFile.exists() && sourceFile.isFile()) ) { + alert("Invalid source file path."); + window.close(); + return; + } + sourceURI = cmdLine.resolveURI(sourceFilePath); + + // create a nsIFile object for the output file + try{ + destFile = cmdLine.resolveURI(destFilePath).QueryInterface(Components.interfaces.nsIFileURL).file; + }catch(e){ + alert("Invalid destination file.\n\nException:\n" + e); + window.close(); + return; + } + + // add iframeLoaded() as an onload event handler, then navigate to the source file + docFrame.addEventListener("DOMContentLoaded", iframeLoaded, true); + docFrame.setAttribute("src", sourceURI.spec); + + } catch (e) { + alert("Error in init():\n\n" + e); + window.close(); + return; + } +} + +function iframeLoaded() +{ + /* + // print every MathJax signal to the log + docFrame.contentWindow.MathJax.Hub.Startup.signal.Interest( + function (message) {log("Startup: "+message)} + ); + docFrame.contentWindow.MathJax.Hub.signal.Interest( + function (message) {log("Hub: "+message)} + ); + */ + + // tell MathJax to call serialize() when finished + docFrame.contentWindow.MathJax.Hub.Register.StartupHook("End", function() {serialize();}); +} + +function fileURLtoDataURI(url) +{ + var ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var url_object = ios.newURI(url, "", null); + var file = url_object.QueryInterface(Components.interfaces.nsIFileURL).file; + + var data = ""; + var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]. + createInstance(Components.interfaces.nsIFileInputStream); + fstream.init(file, -1, -1, false); + var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]. + createInstance(Components.interfaces.nsIBinaryInputStream); + bstream.setInputStream(fstream); + + var bytes = bstream.readBytes(bstream.available()); + b64bytes = btoa(bytes); + + return "data:;base64," + b64bytes; + +} + +function serialize() +{ + var MathJaxURL = docFrame.contentWindow.MathJax.Hub.config.root; + + var searchURIList = new Array(); + var replacementURIList = new Array(); + + log("serialize: preprocessing"); + + // remove the MathJax status message window + msgdiv = docFrame.contentDocument.getElementById("MathJax_Message"); + msgdiv.parentNode.removeChild(msgdiv); + + /* Loop through all CSS rules to find all @font-face rules. + At this point, they refer to local absolute paths using file:// URLs. + Replace them either with appropriate URLs relative to finalMathJaxURL + or with data URIs. */ + + for (var i = 0; i tag + try{ + var scriptTags = docFrame.contentDocument.getElementsByTagName("script"); + for (var i=0; i + + + + +