#+TITLE: How to circumvent ncf limitation of MathToWeb with Plastex? #+AUTHOR: Jambunathan K #+EMAIL: kjambunathan@gmail.com #+DATE: 2011-11-01 Tue #+DESCRIPTION: #+KEYWORDS: #+LANGUAGE: en #+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc #+EXPORT_SELECT_TAGS: export #+EXPORT_EXCLUDE_TAGS: noexport #+LINK_UP: #+LINK_HOME: #+XSLT: #+LATEX_HEADER: \usepackage{jambu} * Summary This document outlines ways to circumvent limitations of "-ncf" option in MathToWeb. See this [[http://lists.gnu.org/archive/html/emacs-orgmode/2011-11/msg00017.html][discussion thread]] for understanding of the limitations. * Settings Leave the converter command at it's default value - which doesn't use =-ncf= option. #+begin_src emacs-lisp (setq org-latex-to-mathml-convert-command "java -jar %j -unicode -force -df %o %I ") #+end_src * mysttyle.tex In the definitions below, one =newcommand= uses one another =newcommand=. The below defintions goes in to user specified stlyes file =mystyle.tex=. #+begin_src tex \newcommand{\pressure}{p} \newcommand{\capillaryPressure}{\pressure_{c}} #+end_src * LaTeX Equation The latex equation below relies on above newcommand definitions to be available. #+begin_src org ,#+LABEL: Equation:cp ,\begin{equation} ,\capillaryPressure=0 ,\end{equation} #+end_src #+LABEL: Equation:cp \begin{equation} \capillaryPressure=0 \end{equation} * Flatten equations with Plastex Use [[http://wiki.lyx.org/LaTeX/ExpandNewcommands][plastex]] to flatten out the above equation. The snippet below is a variation of script in the afore-mentioned link and takes input from stdin and spews out flattened equation to stdout. Copy the below script to =fixup.py=. #+srcname: fixup.py #+begin_src python #!/usr/bin/python # _*_ coding: UTF-8 _*_ import sys from plasTeX.TeX import TeX doc = TeX(file=sys.stdin).parse() # The processed document is contained in the string doc.source # Print to file # f = open('PlastexProcessed.tex', 'w') sys.stdout.write(doc.source.encode('utf-8')) # f.close() #+end_src * Hack Org with a defadvice "sneak-in" custom processing in to org core by installing the advice below. #+begin_src emacs-lisp (defadvice org-format-latex-as-mathml (before my-org-format-latex-as-mathml activate) "Prepend mystyle.tex to latex-frag. Pass it through to \"plastex\". Use the flattened equation - which has ZERO DEPENDENCIES on user's newcommand definitions - as input to MathToWeb." (ad-set-arg 0 (and (ad-get-arg 0) (with-temp-buffer (insert-file-contents "mystyle.tex") (goto-char (point-max)) (newline) (insert (ad-get-arg 0)) (shell-command-on-region (point-min) (point-max) "./fixup.py" nil t (get-buffer-create "*plastex-errors*")) (buffer-string))))) #+end_src * Export Export this file to ODT and see that above LaTeX equation is satisfactorily converted to MathML by MathToWeb. * Disabling above advice You can disable the above advice anytime by doing this. #+begin_src emacs-lisp (ad-disable-advice 'org-format-latex-as-mathml 'before 'my-org-format-latex-as-mathml) (ad-update 'org-format-latex-as-mathml) #+end_src