public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Richard Huntsinger <rhuntsinger-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Jupyter-to-LaTex | How to render tables?
Date: Thu, 21 Jul 2022 13:29:28 -0700 (PDT)	[thread overview]
Message-ID: <8b4c2a80-b8bd-4d2f-b02d-c61370921882n@googlegroups.com> (raw)
In-Reply-To: <ebb070e8-7bcc-4584-b142-5a4a150def08n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 3322 bytes --]

I've come to better overall solution.  Rather than have pandoc convert HTML 
tables to LaTex tables, I've coded the tables in both HTML and LaTex format 
within the Jupyter notebook.  The HTML representation will be rendered when 
running Jupyter; the LaTex representation will be copied as-is by pandoc 
when converting from Jupyter-format to LaTeX format.

x = data.frame(a=c(1,2,3), b=c(10,20,30), c=c(100,200,300))
x.html = kable(x, format=“html”, escape=FALSE, align=rep(“r”, ncol(x)), 
caption=“This is from HTML”, row.names=FALSE, 
table.attr=“style="white-space: nowrap;"”)
x.latex = kable_styling(latex_options=c(“hold_position”),
kable(x, format=“latex”, escape=FALSE, align=rep(“r”, ncol(x)), 
caption=“This is from LaTex”, row.names=FALSE))
mbx = list(data=list(“text/html”=as.character(x.html), 
“text/latex”=as.character(x.latex)), metadata=NULL)
publish_mimebundle(mbx$data, mbx$metadata)

On Tuesday, July 19, 2022 at 10:17:07 AM UTC-7 Richard Huntsinger wrote:

> The following lua code does the trick - it captures Jupyter's html tables 
> and converts them to latex tables for rendering in PDF.
>
> function RawBlock (raw)
>     if raw.format:match 'html' then 
>         return pandoc.read(raw.text, 'html').blocks 
>     end 
> end
>
> New problem exposed, though.  Nested tables are not converted properly.  
> I'll treat this conversation re: adjusting for html code as resolved, and 
> I'll open a new conversation re: converting nested tables.
> On Monday, July 18, 2022 at 6:40:36 PM UTC-7 Richard Huntsinger wrote:
>
>> Thank you much, fiddlosopher, for your quick reply.  Clearly, I need make 
>> use of lua filters to adjust for the HTML code in my Jupyter notebooks.  
>> I've now read the lua documentation and tried some of the examples on the 
>> pandoc doc site and pandoc/lua-filters repository - but I don't see an 
>> example of how to search for and transform HTML-format tables to native 
>> pandoc-format tables, or similar such thing.  Can you provide me some 
>> additional guidance?   
>>
>> On Monday, July 18, 2022 at 12:54:17 AM UTC-7 fiddlosopher wrote:
>>
>>> Raw HTML in a Markdown document (which is apparently what the R 
>>> display_html function produces) will not be passed through to PDF. 
>>> Similarly, raw LaTeX will not be passed through to HTML. 
>>>
>>> One approach might be to generate *both* formats in your notebook. You 
>>> could try that. 
>>>
>>> Another approach would be to use a Lua filter that matches raw HTML 
>>> blocks and uses pandoc.read to convert them to native pandoc tables, which 
>>> could then be rendered in PDF. I believe there are examples of such filters 
>>> either in the Lua filters documentation, or in the pandoc/lua-filters 
>>> repository, or on this list. If you can't see how to do it, just ask. 
>>>
>>>
>>>

-- 
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/8b4c2a80-b8bd-4d2f-b02d-c61370921882n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 4254 bytes --]

      parent reply	other threads:[~2022-07-21 20:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6c82ec4b-d697-41a6-9192-2a84945e0850n@googlegroups.com>
2022-07-17 23:40 ` Richard Huntsinger
     [not found] ` <6c82ec4b-d697-41a6-9192-2a84945e0850n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-07-18  7:54   ` John MacFarlane
     [not found]     ` <5299A394-419C-4839-B528-46D002AF3371-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-07-19  1:40       ` Richard Huntsinger
     [not found]         ` <1568e512-a488-495c-a82d-aedec432d0acn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-07-19 17:17           ` Richard Huntsinger
     [not found]             ` <ebb070e8-7bcc-4584-b142-5a4a150def08n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-07-21 20:29               ` Richard Huntsinger [this message]

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=8b4c2a80-b8bd-4d2f-b02d-c61370921882n@googlegroups.com \
    --to=rhuntsinger-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).