public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Bernie Roesler <bernard.roesler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
Cc: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Markdown Fenced Div to LaTeX Environment
Date: Thu, 28 Jan 2021 14:24:32 -0500	[thread overview]
Message-ID: <0F730DD9-8029-462F-A65E-AD3E618118E4@gmail.com> (raw)
In-Reply-To: <m2ft2l7zrz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>

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

Ah, excellent. The additional div makes a big difference in processing.

I realized I over-simplified my example. It's actually:

\begin{algorithm}
	\caption{...}
	\label{alg:my_alg}
	\begin{algorithmic}
	...statements...
	\end{algorithmic}
\end{algorithm}

"algorithm" is just a float like "figure" or "table", and "algorithmic" actually defines the commands "\Require", etc. pandoc now makes divs for both algorithm and algorithmic, but still loses the commands, as you've mentioned.

I've just been using a bash/sed script to pre-process the latex document before processing with pandoc which seems to work well for now.

Thanks for the update!

-Bernie


------------------
for reference, I'm now using:
------------------
$ pandoc --version
pandoc 2.11.4
Compiled with pandoc-types 1.22, texmath 0.12.1, skylighting 0.10.2,
citeproc 0.3.0.5, ipynb 0.1.0.1
User data directory: /Users/bernardroesler/.local/share/pandoc or /Users/bernardroesler/.pandoc
Copyright (C) 2006-2021 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.


> On Jan 28, 2021, at 12:10, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
> 
> 
> Pandoc's latex reader doesn't know about the algorithm
> environment. What package defines it?
> 
> With the latest pandoc release, we get this output with
> pandoc -f latex -t html --mathjax on your input:
> 
> <div class="algorithm">
> <p><span class="math inline">\(x &gt; 0\)</span>. <span class="math inline">\(x \gets x^2\)</span> <span class="math inline">\(x\)</span></p>
> </div>
> 
> Better, though we lose the line breaks and we lose \Require, etc.
> 
> If you want to handle this properly, one option would be to use
> pandoc -f latex+raw_tex --lua-filter handle_algorithm.lua
> 
> You'd have to write handle_algorithm.lua, but what it would do
> is find raw latex blocks with algorithm environments and convert
> them to some form that works in your Jekyll blog.
> 
> You might also try this approach:
> 
> Add macro definitions to your latex:
> 
> \renewcommand{\Require}{1]{Require #1}
> 
> and so on for \State and \Procedure.
> 
> Then pandoc will parse them and you'll get better output. That
> gets you almost all the way there, except for the newlines and
> whitespace, if they're significant in this environment.
> 
> For the newlines, you could add a filter that intercepts
> SoftBreak.
> 
> 
> 
> Bernie Roesler <bernard.roesler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:bernard.roesler@gmail.com>> writes:
> 
>> Hi all,
>> 
>> Is there a *reverse* of this solution? I'm trying to go from LaTeX to 
>> markdown/html for posting to a Jekyll blog, but pandoc parses out much of 
>> the algorithm/algorithmic environments, and does not put the contents in a 
>> div like it does for theorems/proofs.
>> 
>> With the input:
>> 
>> \begin{algorithm}
>>    \Require $x > 0$.
>>    \Procedure{SquareX}{$x$}
>>      \State $x \gets x^2$
>>      \State \Return $x$
>>    \EndProcedure
>> \end{algorithm}
>> 
>> Currently the output is:
>> 
>> $x > 0$. $x \gets x^2$ $x$
>> 
>> I'd like to have to something like:
>> 
>> <div class="algorithm">
>>    <span class="Require">$x > 0$</span>
>>    <span class="Procedure">SquareX</span>($x$)
>>    <span class="State">$x \gets x^2$</span>
>>    <span class="State" class="Return">$x$</span>
>>    <span class="EndProcedure"></span>
>> </div>
>> 
>> or something to that effect to allow formatting of the individual elements.
>> 
>> See also my StackOverflow question 
>> <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment>>
>> and Jekyll Talk discussion 
>> <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler>>
>> .
>> 
>> I can do my own wrangling and add a verbatim environment before running it 
>> through pandoc and then parse that chunk of the markdown file afterwards, 
>> but I was curious if there was a more elegant solution to dealing with 
>> unknown environments.
>> 
>> Thanks,
>> Bernie
>> 
>> On Sunday, January 24, 2021 at 2:51:02 PM UTC-5 chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <http://gmail.com/> wrote:
>> 
>>> Thanks! Exactly what i needed to know. 
>>> 
>>> -Chris
>>> 
>>> On Sun, Jan 24, 2021, 11:58 AM John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org <http://berkeley.edu/>> wrote:
>>> 
>>>> 
>>>> You need a filter, but it would be a simple one.
>>>> 
>>>> Something like
>>>> 
>>>> function latex(s)
>>>>  return pandoc.RawBlock('latex', s) 
>>>> end
>>>> 
>>>> function Div(el)
>>>>  if el.classes[1] == 'solution' then
>>>>    return { latex('\begin{solution}'), el.content, 
>>>> latex('\end{solution}') }
>>>>  end
>>>> end
>>>> 
>>>> Chris Diaz <chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <http://gmail.com/>> writes:
>>>> 
>>>>> Hello,
>>>>> 
>>>>> I'm looking for advice on how to produce HTML and LaTeX from Markdown 
>>>> using 
>>>>> fenced divs (or something else) to apply custom styles to specific 
>>>> portions 
>>>>> of the document. 
>>>>> 
>>>>> For example, I'm hoping to write something like this:
>>>>> 
>>>>> ::: solution
>>>>> Solution text here.
>>>>> :::
>>>>> 
>>>>> in order to produce this when HTML is the output (already works):
>>>>> 
>>>>> <div class="solution">
>>>>> Solution text here.
>>>>> </div>
>>>>> 
>>>>> and this when LaTeX/PDF is the output:
>>>>> 
>>>>> \begin{solution}
>>>>> Solution text here.
>>>>> \end{solution}
>>>>> 
>>>>> This idea comes from Bookdown's 
>>>>> <https://bookdown.org/yihui/bookdown/custom-blocks.html <https://bookdown.org/yihui/bookdown/custom-blocks.html>> Custom Blocks 
>>>>> feature, but I'm wondering if there's a way to do this with Pandoc, or 
>>>> if 
>>>>> this would require a Lua filter. 
>>>>> 
>>>>> Thanks,
>>>>> Chris
>>>>> 
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>> Groups "pandoc-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <http://googlegroups.com/>.
>>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.com>
>>>> .
>>>> 
>>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.com>.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/0F730DD9-8029-462F-A65E-AD3E618118E4%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 35653 bytes --]

  parent reply	other threads:[~2021-01-28 19:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-24 13:47 Chris Diaz
     [not found] ` <8ba84992-d792-4333-aae0-560147ef79d4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-01-24 14:32   ` Albert Krewinkel
     [not found]     ` <87pn1uwglb.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2021-01-24 17:35       ` Bastien DUMONT
2021-06-16 14:37       ` Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment) 'juh' via pandoc-discuss
2021-06-16 15:48         ` AW: " denis.maier-NSENcxR/0n0
     [not found]           ` <5db56b4f1d8d4ca2bec612bcebb7a525-NSENcxR/0n0@public.gmane.org>
2021-06-16 21:59             ` Bastien DUMONT
2021-06-17  6:27               ` 'juh' via pandoc-discuss
     [not found]                 ` <493d0aa9-47f5-ca8d-2ef5-8e63f965c529-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2021-06-17  6:54                   ` BPJ
     [not found]                     ` <CADAJKhDmtv1iLv8GsKzjxSzmvHzuOfpP6qrc21TUEYturw_xTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-06-17  7:55                       ` 'juh' via pandoc-discuss
     [not found]                         ` <dc8ef20b-4a8b-c385-704c-28c85a5b6820-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2021-06-17  8:12                           ` AW: " denis.maier-NSENcxR/0n0
     [not found]                             ` <4396a9133ab74e4fbff486f09e22d254-NSENcxR/0n0@public.gmane.org>
2021-06-17  8:36                               ` Bastien DUMONT
2021-06-17  8:51                                 ` AW: " denis.maier-NSENcxR/0n0
2021-06-17 10:20                                 ` 'juh' via pandoc-discuss
     [not found]                                   ` <af60ed15-0d8c-5c51-5a34-a9c082e7fc89-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2021-06-17 11:44                                     ` Bastien DUMONT
2021-06-17 12:23                                     ` AW: " denis.maier-NSENcxR/0n0
2021-06-17  8:18                           ` Bastien DUMONT
2021-01-24 17:58   ` Markdown Fenced Div to LaTeX Environment John MacFarlane
     [not found]     ` <m2lfcigqtj.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2021-01-24 19:50       ` Chris Diaz
     [not found]         ` <CAMkDs=NHev6VHpGEq6qiYGbOMgMr6RqKzu0E9dcsr1kZFXO-Ow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-01-28  3:17           ` Bernie Roesler
     [not found]             ` <e6363602-852a-45a1-a199-81553da1966bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-01-28 17:10               ` John MacFarlane
     [not found]                 ` <m2ft2l7zrz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2021-01-28 19:24                   ` Bernie Roesler [this message]
     [not found]                     ` <0F730DD9-8029-462F-A65E-AD3E618118E4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-01-28 19:52                       ` Bernie Roesler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0F730DD9-8029-462F-A65E-AD3E618118E4@gmail.com \
    --to=bernard.roesler-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).