anammari / pandoc

Automatically exported from code.google.com/p/pandoc
GNU General Public License v2.0
0 stars 0 forks source link

Doing something of LaTeX commands when generating HTML #198

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I use Pandoc to generate both LaTeX and HTML. One
troublesome thing with this is that if one has
literal LaTeX commands in the markdown these just
vanish if one tries to generate HTML from the same
markdown. It would be much better if they were
turned into HTML spans with the LaTeX command name
as a class and the argument(s) as content.  Then
one could still make the text make sense, and do
something sensible with those spans, including
setting them to display: none, *if* that's the
sensible thing to do!  Thus

    \foo{bar}

would be HTML-ified as 

    <span class="foo">bar</span>

and

    \foo{bar}{baz}{biz}

would become

    <span class="foo">
      <span class="arg1">bar</span>
      <span class="arg2">baz</span>
      <span class="arg3">biz</span>
    </span>

which would increase once chances of making something
sensible of them with CSS.

Needless to say \begin{foo} and \end{foo} should be special
and become <div class="foo"> and </div> respectively (and 
arguments to the environment becoming additional classes).

As long as ones LaTeX commands are relatively
simple -- and I at least mostly use them for font
changes and the like -- this would be much better
than getting nothing!  Clearly it wouldn't make
much sense to generate HTML from markdown which
contains a lot of *complicated* LaTeX anyway.
However it might be a good idea to have a command
line switch with a filename as an optional
argument: if the switch is present LaTeX commands
will be turned into HTML spans and if the filename
is present it contains a list of LaTeX commands
which will just be deleted, alternatively ones
which will be turned into HTML spans.

Original issue reported on code.google.com by bpjonsson@gmail.com on 7 Jan 2010 at 4:48

GoogleCodeExporter commented 9 years ago
I wonder whether this would be a way to enable language tagging when converting 
from
LaTeX to HTML.

Original comment by google-c...@pragmata.tk on 10 Jan 2010 at 11:20

GoogleCodeExporter commented 9 years ago
I was just thinking about this too. Specifically I'd like to get label and ref 
tags and use javascript for cross referencing figs and math with numbering.

Original comment by mpastell on 7 Jan 2011 at 11:21

GoogleCodeExporter commented 9 years ago
Handling \ref and \label in a cross-platform way is very complicated.

If you just want automatic numbering of equations, with the ability to refer 
back, you should try the auto-numbered examples in pandoc's markdown:

(@myeqn)  $e=mc^2$

As shown in ___, (@myeqn) is a refinement of ...

Original comment by fiddloso...@gmail.com on 7 Jan 2011 at 5:16

GoogleCodeExporter commented 9 years ago
Thanks for the quick comment. Numbered examples are nice, but not quite enough 
for what I need in all cases. 

Would you still consider adding ref and label support to pandoc extended 
markdown syntax and reader? Latex and texinfo 
(http://www.gnu.org/software/hello/manual/texinfo/ref.html) can do this and in 
HTML you could use the ID tag for labels and refs would be fairly easy to 
handle with javascript. 

Of course using labels would require the ability to specify the label for 
figures, tables, equations and code so I know this requires some changes. 

Original comment by mpastell on 10 Jan 2011 at 10:24

GoogleCodeExporter commented 9 years ago
What would \ref{foo} and \label{foo} be rendered as in HTML?

In LaTeX you might have:

In figure~\ref{fig1} in section~\ref{sec1}, ...

To render this properly, pandoc would have to know that fig1 is a label for a 
figure, and sec1 for a section, and pandoc would have to keep track of 
numbering for both.  In addition there's the problem that default HTML and 
LaTeX output in pandoc doesn't number sections.

Original comment by fiddloso...@gmail.com on 10 Jan 2011 at 4:10

GoogleCodeExporter commented 9 years ago
I think \ref{foo} could be rendered as <span class="ref">foo</a> as suggested
by bpjonsson above. And \label{foo} could become <div id="foo">. Then
pandoc would not need to handle the numbering and cross-refences and
they could be later processed e.g. with javascript to produce figure
numbers and references.

For figures Pandoc could use the title argument as label and ID as follows:

![Some caption](myfig.png "mylabel")

In HTML:

<div class="figure">
     <img src="myfig.png" title="mylabel" alt="Some caption"/>
     <p class="caption" id="mylabel">Some caption</p>
</div>

And in Latex:

\begin{figure}[htb]
    \centering
    \includegraphics{myfig.png}
    \label{mylabel} 
    \caption{Some caption}
\end{figure}

I guess tables and equations would need some additional syntax to add
labels and table and fig captions need to have a different class in HTML.

I think I should be able to produce the required javascript and I'm
also willing to help out otherwise, but I'm just beginning with Haskell.

Original comment by mpastell on 10 Jan 2011 at 6:35

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Has there been any further discussion on the topic of embedding \ref constructs 
in Pandoc markdown text? I am using the markdown2pdf wrapper and Pandoc v1.8.2. 
 Not able to get reference numbers other than 1 from the following:

Figure \ref{fig:NIARM-TEST1} test for "Figure 1" label.

![Caption for FIG TEST1](../images/TBD.png "fig:NIARM-TEST1")

Figure \ref{fig:NIARM-TEST2} test for "Figure 2" label.

![Caption for FIG TEST2](../images/TBD.png "fig:NIARM-TEST2")

Figure \ref{fig:NIARM-TEST3} test for "Figure 3" label.

\label{fig:NIARM-TEST3}

![Caption for FIG TEST3](../images/TBD.png "fig:NIARM-TEST3")

The first 2 figure references generate ?? as in:

    Figure ?? test for "Figure 2" label.

This caused me to try an explicit \label on Test3, which generates:

    Figure 1 test for "Figure 3" label.

instead of:

     Figure 3 test for "Figure 3" label.

I am new to using Pandoc - maybe I am not using the current syntax.

Original comment by ralp...@gmail.com on 13 Sep 2011 at 6:20

GoogleCodeExporter commented 9 years ago
Did you find an answer to this. I'm trying to get the figure referencing thing 
working too.
thanks

Original comment by IvoJimenez on 22 Oct 2011 at 5:11