emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [odt] regression in using an equation sourced via latex_header
@ 2011-11-01 16:10 Myles English
  2011-11-01 19:10 ` Jambunathan K
  0 siblings, 1 reply; 6+ messages in thread
From: Myles English @ 2011-11-01 16:10 UTC (permalink / raw)
  To: emacs-orgmode Mode


Hello,

If I have a latex file mystyle.tex that contains:

\newcommand{\myBigEquation}{b=23}

and then have this in my org file:

#+LATEX_HEADER: \usepackage{/path/to/mystyle}

I can use it conveniently like this:

\begin{equation}
     \myBigEquation
\end{equation}

and that exports fine to pdf but not to odt.  I am fairly sure it used
to work (around 7th Oct).  Can anyone confirm this?

Myles

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [odt] regression in using an equation sourced via latex_header
  2011-11-01 16:10 [odt] regression in using an equation sourced via latex_header Myles English
@ 2011-11-01 19:10 ` Jambunathan K
  2011-11-01 19:14   ` Jambunathan K
  0 siblings, 1 reply; 6+ messages in thread
From: Jambunathan K @ 2011-11-01 19:10 UTC (permalink / raw)
  To: emacs-orgmode Mode


Myles

Thanks for exercising the latex-to-mathml changes. I am happy that there
is someone out there interested in and using stuff that I have spent
some efforts on.

> Hello,
>
> If I have a latex file mystyle.tex that contains:
>
> \newcommand{\myBigEquation}{b=23}
>
> and then have this in my org file:
>
> #+LATEX_HEADER: \usepackage{/path/to/mystyle}
>
> I can use it conveniently like this:
>
> \begin{equation}
>      \myBigEquation
> \end{equation}
>
> and that exports fine to pdf but not to odt.  I am fairly sure it used
> to work (around 7th Oct).  Can anyone confirm this?

I am using the very latest version in the git. While exporting to odt
using

1. dvipng 
   - I see no issues [1]

2. mathml
   - You need to register your command file with -ncf argument.

     For example, if I put the mystyle.tex in the same directory as
     exported .org file and add the -ncf argument to the converter as
     below

     #+begin_src emacs-lisp
     (setq org-latex-to-mathml-convert-command
           "java -jar %j -ncf mystyle.tex -unicode -force -df %o %I ")
     #+end_src

     I see that your sample file gets exported just fine.

Side Note:
==========

1. You don't have to export the whole file to see whether the
   latex-mathml conversion is sane.

   You can mark - as in marking a region - the LaTeX fragment in your
   org file and do a M-x org-create-math-formula. You will see something
   like this echoed in you *Messages* buffer.

,---- M-x org-create-math-formula
| Mark set [2 times]
| Mark activated
| Wrote ~/tmp-myles/ltxmathml-in3272esr
| Running java -jar ~/tmp-odt/mathtoweb.jar -ncf mystyle.tex -unicode -force -df ltxmathml-out3272r2x ltxmathml-in3272esr 
| <?xml version="1.0" encoding="UTF-8"?>
| <math xmlns="http://www.w3.org/1998/Math/MathML">
| <mrow>
| 	<mspace width="1.00em" />
| 	<mi>b</mi>
| 	<mo>=</mo>
| 	<mn>23</mn>
| </mrow>
| </math>
`----

2. I am copy pasting the extra "stuff" that gets attached to the latex
   fragment before it get "latex" ed and "dvipng"ed.

   latex-to-mathml converter ignores *all* of the stuff that goes in
   org-format-latex-header, org-export-latex-default-packages-alist,
   org-export-latex-packages-alist, org-format-latex-header-extra
   variables.

   I think I should build an "ncf" file on the fly based on these
   variables and pass it to the command line converter.

   Since I don't know much of latex, can you or someone in the list give
   me pointers on what would constitute an ncf argument as expected by
   mathtoweb.

   I will make the needed changes as required.
   
,---- See org-create-formula-image
|     (with-temp-file texfile
|       (insert (org-splice-latex-header
| 	       org-format-latex-header
| 	       org-export-latex-default-packages-alist
| 	       org-export-latex-packages-alist t
| 	       org-format-latex-header-extra))
|       (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
|       (require 'org-latex)
|       (org-export-latex-fix-inputenc))
`----

,---- temporary tex file [see LATEX-HEADER at the end]
| \documentclass{article}
| \usepackage[usenames]{color}
| \usepackage{amsmath}
| \usepackage[mathscr]{eucal}
| \pagestyle{empty}             % do not remove
| \usepackage{pdfpages}
| \usepackage[utf8]{inputenc}
| \usepackage[T1]{fontenc}
| % Package fixltx2e omitted
| \usepackage{graphicx}
| % Package longtable omitted
| % Package float omitted
| % Package wrapfig omitted
| \usepackage{soul}
| \usepackage{t1enc}
| \usepackage{textcomp}
| \usepackage{amssymb}
| % Package hyperref omitted
| \tolerance=1000
| % The settings below are copied from fullpage.sty
| \setlength{\textwidth}{\paperwidth}
| \addtolength{\textwidth}{-3cm}
| \setlength{\oddsidemargin}{1.5cm}
| \addtolength{\oddsidemargin}{-2.54cm}
| \setlength{\evensidemargin}{\oddsidemargin}
| \setlength{\textheight}{\paperheight}
| \addtolength{\textheight}{-\headheight}
| \addtolength{\textheight}{-\headsep}
| \addtolength{\textheight}{-\footskip}
| \addtolength{\textheight}{-3cm}
| \setlength{\topmargin}{1.5cm}
| \addtolength{\topmargin}{-2.54cm}
| 
| \usepackage{jambu}
| \begin{document}
| \begin{equation}
|      \myBigEquation
| \end{equation}
| \end{document}
`----

Footnotes: 

[1]  LaTeX novice here. 

The method I used is this: Put that style file in one of the local
directories and register that directory as a root with the MikTex
package manager. Then use this directive:
\usepackage{jambu}

ps: I am on Windows using Cygwin. So getting the directory path right
with escaping - what with spaces in directories - is always a
hair-splitting experience for me.

     
> Myles
>
>



-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [odt] regression in using an equation sourced via latex_header
  2011-11-01 19:10 ` Jambunathan K
@ 2011-11-01 19:14   ` Jambunathan K
  2011-11-02 21:38     ` Myles English
  0 siblings, 1 reply; 6+ messages in thread
From: Jambunathan K @ 2011-11-01 19:14 UTC (permalink / raw)
  To: emacs-orgmode Mode

> 2. mathml
>    - You need to register your command file with -ncf argument.
>
>      For example, if I put the mystyle.tex in the same directory as
>      exported .org file and add the -ncf argument to the converter as
>      below
>
>      #+begin_src emacs-lisp
>      (setq org-latex-to-mathml-convert-command
>            "java -jar %j -ncf mystyle.tex -unicode -force -df %o %I ")
>      #+end_src
>

ncf option is documented here:
http://www.mathtoweb.com/cgi-bin/mathtoweb_users_guide.pl#Using_newcommand_and_renewcommand

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [odt] regression in using an equation sourced via latex_header
  2011-11-01 19:14   ` Jambunathan K
@ 2011-11-02 21:38     ` Myles English
  2011-11-03 14:59       ` Myles English
  0 siblings, 1 reply; 6+ messages in thread
From: Myles English @ 2011-11-02 21:38 UTC (permalink / raw)
  To: emacs-orgmode

>> On Wed, 02 Nov 2011 00:44:57 +0530, Jambunathan K said:

  >> 2. mathml - You need to register your command file with -ncf
  >> argument.
  >> 
  >> For example, if I put the mystyle.tex in the same directory as
  >> exported .org file and add the -ncf argument to the converter as
  >> below
  >> 
  >> #+begin_src emacs-lisp (setq org-latex-to-mathml-convert-command
  >> "java -jar %j -ncf mystyle.tex -unicode -force -df %o %I ")
  >> #+end_src
  >> 

  > ncf option is documented here:
  > http://www.mathtoweb.com/cgi-bin/mathtoweb_users_guide.pl#Using_newcommand_and_renewcommand

I have narrowed the problem I am having down to newcommands that build
on other newcommands, like so ...

If I have this in my style file:

\newcommand{\pressure}{p}
\newcommand{\capillaryPressure}{\pressure_{c}}

and try to use it like this:

#+LABEL: Equation:cp
     \begin{equation}
     \capillaryPressure=0
     \end{equation}

then I get this xml:

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
	<mspace width="1.00em" />
	\pressur
	<msub>
		<mi>e</mi>
		<mi>c</mi>
	</msub>
	<mo>=</mo>
	<mn>0</mn>
</mrow>
</math>

when what I expected was P_c .

Any ideas?

Myes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [odt] regression in using an equation sourced via latex_header
  2011-11-02 21:38     ` Myles English
@ 2011-11-03 14:59       ` Myles English
  2011-11-03 18:21         ` Plastex + MathToWeb (was Re: [odt] regression in using an equation sourced via latex_header) Jambunathan K
  0 siblings, 1 reply; 6+ messages in thread
From: Myles English @ 2011-11-03 14:59 UTC (permalink / raw)
  To: emacs-orgmode Mode

>> On Wed, 02 Nov 2011 21:38:42 +0000, Myles English said:

>> On Wed, 02 Nov 2011 00:44:57 +0530, Jambunathan K said:
  >>> 2. mathml - You need to register your command file with -ncf
  >>> argument.
  >>> 
  >>> For example, if I put the mystyle.tex in the same directory as
  >>> exported .org file and add the -ncf argument to the converter as
  >>> below
  >>> 
  >>> #+begin_src emacs-lisp (setq org-latex-to-mathml-convert-command
  >>> "java -jar %j -ncf mystyle.tex -unicode -force -df %o %I ")
  >>> #+end_src
  >>> 

  >> ncf option is documented here:
  >> http://www.mathtoweb.com/cgi-bin/mathtoweb_users_guide.pl#Using_newcommand_and_renewcommand

  > I have narrowed the problem I am having down to newcommands that
  > build on other newcommands, like so ...

  > If I have this in my style file:

  > \newcommand{\pressure}{p}
  > \newcommand{\capillaryPressure}{\pressure_{c}}

This can work if the style file appears twice in the mathml command:

#+begin_src emacs-lisp
      (setq org-latex-to-mathml-convert-command
            "java -jar %j -ncf mystyle.sty,mystyle.sty -unicode -force -df %o %I ")
#+end_src


Myles

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Plastex + MathToWeb (was Re: [odt] regression in using an equation sourced via latex_header)
  2011-11-03 14:59       ` Myles English
@ 2011-11-03 18:21         ` Jambunathan K
  0 siblings, 0 replies; 6+ messages in thread
From: Jambunathan K @ 2011-11-03 18:21 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1548 bytes --]

Myles English <mylesenglish@gmail.com> writes:

>>> On Wed, 02 Nov 2011 21:38:42 +0000, Myles English said:
>
>>> On Wed, 02 Nov 2011 00:44:57 +0530, Jambunathan K said:
>   >>> 2. mathml - You need to register your command file with -ncf
>   >>> argument.
>   >>> 
>   >>> For example, if I put the mystyle.tex in the same directory as
>   >>> exported .org file and add the -ncf argument to the converter as
>   >>> below
>   >>> 
>   >>> #+begin_src emacs-lisp (setq org-latex-to-mathml-convert-command
>   >>> "java -jar %j -ncf mystyle.tex -unicode -force -df %o %I ")
>   >>> #+end_src
>   >>> 
>
>   >> ncf option is documented here:
>   >> http://www.mathtoweb.com/cgi-bin/mathtoweb_users_guide.pl#Using_newcommand_and_renewcommand
>
>   > I have narrowed the problem I am having down to newcommands that
>   > build on other newcommands, like so ...
>
>   > If I have this in my style file:
>
>   > \newcommand{\pressure}{p}
>   > \newcommand{\capillaryPressure}{\pressure_{c}}
>
> This can work if the style file appears twice in the mathml command:
>
> #+begin_src emacs-lisp
>       (setq org-latex-to-mathml-convert-command
>             "java -jar %j -ncf mystyle.sty,mystyle.sty -unicode -force -df %o %I ")
> #+end_src

Where from you pulled this trick. Unless it is documented somewehere you
are most likely relying on an unintentional side-effect. 

After some googling, I see that there is promising solution using
plastex. The solution is documented in the below file. The customary odt
file is attached as a proof-of-concept.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mathtoweb-with-plastex.org --]
[-- Type: text/x-org, Size: 3565 bytes --]

#+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

[-- Attachment #3: Type: text/plain, Size: 5 bytes --]


-- 

[-- Attachment #4: mathtoweb-with-plastex.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 11814 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-11-03 18:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-01 16:10 [odt] regression in using an equation sourced via latex_header Myles English
2011-11-01 19:10 ` Jambunathan K
2011-11-01 19:14   ` Jambunathan K
2011-11-02 21:38     ` Myles English
2011-11-03 14:59       ` Myles English
2011-11-03 18:21         ` Plastex + MathToWeb (was Re: [odt] regression in using an equation sourced via latex_header) Jambunathan K

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).