From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31051 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Huntsinger Newsgroups: gmane.text.pandoc Subject: Re: Jupyter-to-LaTex | How to render tables? Date: Thu, 21 Jul 2022 13:29:28 -0700 (PDT) Message-ID: <8b4c2a80-b8bd-4d2f-b02d-c61370921882n@googlegroups.com> References: <6c82ec4b-d697-41a6-9192-2a84945e0850n@googlegroups.com> <5299A394-419C-4839-B528-46D002AF3371@gmail.com> <1568e512-a488-495c-a82d-aedec432d0acn@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_538_89730427.1658435368655" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28809"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCFYNC6M64FBBKXO42LAMGQEIHPBUUA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Jul 21 22:29:34 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-yb1-f190.google.com ([209.85.219.190]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oEcnd-0007GW-Ee for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 21 Jul 2022 22:29:33 +0200 Original-Received: by mail-yb1-f190.google.com with SMTP id f85-20020a253858000000b00670a44473e2sf2056371yba.9 for ; Thu, 21 Jul 2022 13:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=ny6jbWJ2hpxxE0vCDLQEB/BIOlDq2B9vVc9eY7bjb40=; b=EXD20qdSwcaRWC6qd4Os+oOpcNt8lWZOTQwXG2wL9mWHynpk6n40gdAedmhMsot1Cp JeyzY2bc3H+YXoH0JpzF3TCmzy65rk4kNnY7u+hX1tLTSeh39HRTGwjWiXWxo6dZsjAl jmFsURTwxNam3wWL/zEyyBMG+nw+dUsVzhH8cyhNPyermX7eZr58gM/D1QNgUA1CdxpE s2CmD703EZviNiJkeZRW3j8nUf5zD5ybYbkx8uOJ8SSEn9pJAXPpc7C+dffl8ahlP4ds gJkxtUUketU2dPtDq60oehYSKz3o69dZeC93FCYr1O4uv5YXv1+X0RglefjJi+IKoG+O quUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berkeley.edu; s=google; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=ny6jbWJ2hpxxE0vCDLQEB/BIOlDq2B9vVc9eY7bjb40=; b=slkyZtr7cfjNhRop5pDqx6TlBTt5IzfpMP2HtK+fHV8yewPjeaNUi3Eeer1m8rBNWK bfIIeU2R4hDjV9Akc7DO5fGBDHQHt2SQ7tUloU6LfRKiC22mhagOouyfNz2rtsVdl2QO X2BlMmcLkv5QW+HRG3SakhTF06bNl/+ZLUJGvrcaLypxpueoFnAEcGwyOAaDTUCDvEMz 9GaCjKrTEfBa588hpfi9Q5ei/e0iRT+ZjEbjq4ZVGFYkBZBG0R6VY4x9sLH+2YOHqfXL jI6c2IgmKXRSPAVlOAo5Q/3yAPxmbooqav/5Z2pcCd+3WuZZPxUmcc4nVsFEDiP+UAXK ajfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=ny6jbWJ2hpxxE0vCDLQEB/BIOlDq2B9vVc9eY7bjb40=; b=e7V5pjR7FVprzcHqaTwcFhtxnS8Iay/yfFO5rx+rHarqnuAEjG2sECiMGJcGw3VrHz aZMVKR2ZbE/5kwrkZGZ+sB8wSfKNeUEfC4Z7bCL3McU13odX1N79i2NMY5zJ14vIXL33 4/VfTrzDTkmgXGaZM3emLrJF3FtZO2edCjwAXL/rdHPdsR2Yj18Xoo69GfOSRCdHbUjt FRhpOTcxofrD5qRy1gR9d1uzjmjDuiYQMWVFaU40Indh5U5E6w9KD0AVBpbKCm6C6F+a ab0A3JgkY2FRt31mSRGMReqbgZ9gMkUn3gYC3e3GzeFih93RNdWZ2jMnuxGKWp4UNy5D rynQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AJIora/7ycVj8pLmq8Akgwdax5rC0O4hF99C3Api0DD9F1c7zZESl6qQ NACIKmi5YFNZ7sqD4cqkVuo= X-Google-Smtp-Source: AGRyM1sDtcDTg3lPmrDIwjamGf2om6CjWXQUNnrkQJekbjSvvCjdDTd2DcObb2H8K9h7jmpQ4TJQzA== X-Received: by 2002:a25:bd83:0:b0:670:c602:db73 with SMTP id f3-20020a25bd83000000b00670c602db73mr297394ybh.502.1658435372266; Thu, 21 Jul 2022 13:29:32 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a25:c754:0:b0:670:6a7e:f2f5 with SMTP id w81-20020a25c754000000b006706a7ef2f5ls2223714ybe.3.-pod-prod-gmail; Thu, 21 Jul 2022 13:29:29 -0700 (PDT) X-Received: by 2002:a05:6902:20a:b0:670:c563:9180 with SMTP id j10-20020a056902020a00b00670c5639180mr281835ybs.401.1658435369350; Thu, 21 Jul 2022 13:29:29 -0700 (PDT) In-Reply-To: X-Original-Sender: rhuntsinger-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:31051 Archived-At: ------=_Part_538_89730427.1658435368655 Content-Type: multipart/alternative; boundary="----=_Part_539_629597917.1658435368655" ------=_Part_539_629597917.1658435368655 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I've come to better overall solution. Rather than have pandoc convert HTML= =20 tables to LaTex tables, I've coded the tables in both HTML and LaTex format= =20 within the Jupyter notebook. The HTML representation will be rendered when= =20 running Jupyter; the LaTex representation will be copied as-is by pandoc=20 when converting from Jupyter-format to LaTeX format. x =3D data.frame(a=3Dc(1,2,3), b=3Dc(10,20,30), c=3Dc(100,200,300)) x.html =3D kable(x, format=3D=E2=80=9Chtml=E2=80=9D, escape=3DFALSE, align= =3Drep(=E2=80=9Cr=E2=80=9D, ncol(x)),=20 caption=3D=E2=80=9CThis is from HTML=E2=80=9D, row.names=3DFALSE,=20 table.attr=3D=E2=80=9Cstyle=3D"white-space: nowrap;"=E2=80=9D) x.latex =3D kable_styling(latex_options=3Dc(=E2=80=9Chold_position=E2=80=9D= ), kable(x, format=3D=E2=80=9Clatex=E2=80=9D, escape=3DFALSE, align=3Drep(=E2= =80=9Cr=E2=80=9D, ncol(x)),=20 caption=3D=E2=80=9CThis is from LaTex=E2=80=9D, row.names=3DFALSE)) mbx =3D list(data=3Dlist(=E2=80=9Ctext/html=E2=80=9D=3Das.character(x.html)= ,=20 =E2=80=9Ctext/latex=E2=80=9D=3Das.character(x.latex)), metadata=3DNULL) 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= =20 > and converts them to latex tables for rendering in PDF. > > function RawBlock (raw) > if raw.format:match 'html' then=20 > return pandoc.read(raw.text, 'html').blocks=20 > end=20 > end > > New problem exposed, though. Nested tables are not converted properly. = =20 > I'll treat this conversation re: adjusting for html code as resolved, and= =20 > 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 mak= e=20 >> use of lua filters to adjust for the HTML code in my Jupyter notebooks. = =20 >> I've now read the lua documentation and tried some of the examples on th= e=20 >> pandoc doc site and pandoc/lua-filters repository - but I don't see an= =20 >> example of how to search for and transform HTML-format tables to native= =20 >> pandoc-format tables, or similar such thing. Can you provide me some=20 >> additional guidance? =20 >> >> 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=20 >>> display_html function produces) will not be passed through to PDF.=20 >>> Similarly, raw LaTeX will not be passed through to HTML.=20 >>> >>> One approach might be to generate *both* formats in your notebook. You= =20 >>> could try that.=20 >>> >>> Another approach would be to use a Lua filter that matches raw HTML=20 >>> blocks and uses pandoc.read to convert them to native pandoc tables, wh= ich=20 >>> could then be rendered in PDF. I believe there are examples of such fil= ters=20 >>> either in the Lua filters documentation, or in the pandoc/lua-filters= =20 >>> repository, or on this list. If you can't see how to do it, just ask.= =20 >>> >>> >>> --=20 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 e= mail 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. ------=_Part_539_629597917.1658435368655 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 r= endered when running Jupyter; the LaTex representation will be copied as-is= by pandoc when converting from Jupyter-format to LaTeX format.

x = =3D data.frame(a=3Dc(1,2,3), b=3Dc(10,20,30), c=3Dc(100,200,300))
x.html= =3D kable(x, format=3D=E2=80=9Chtml=E2=80=9D, escape=3DFALSE, align=3Drep(= =E2=80=9Cr=E2=80=9D, ncol(x)), caption=3D=E2=80=9CThis is from HTML=E2=80= =9D, row.names=3DFALSE, table.attr=3D=E2=80=9Cstyle=3D"white-space: nowrap;= "=E2=80=9D)
x.latex =3D kable_styling(latex_options=3Dc(=E2=80=9Chold_po= sition=E2=80=9D),
kable(x, format=3D=E2=80=9Clatex=E2=80=9D, escape=3DFA= LSE, align=3Drep(=E2=80=9Cr=E2=80=9D, ncol(x)), caption=3D=E2=80=9CThis is = from LaTex=E2=80=9D, row.names=3DFALSE))
mbx =3D list(data=3Dlist(=E2=80= =9Ctext/html=E2=80=9D=3Das.character(x.html), =E2=80=9Ctext/latex=E2=80=9D= =3Das.character(x.latex)), metadata=3DNULL)
publish_mimebundle(mbx$data,= mbx$metadata)


On Tuesday, July 19, 2022 at 10:17:07 AM UTC-7 Richard H= untsinger 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)
=C2=A0 =C2=A0 if raw.format:match 'html' then=C2=A0
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 return pandoc.read(raw.text, 'html').block= s=C2=A0
=C2=A0 =C2=A0 end=C2=A0
end

N= ew problem exposed, though.=C2=A0 Nested tables are not converted properly.= =C2=A0 I'll treat this conversation re: adjusting for html code as reso= lved, and I'll open a new conversation re: converting nested tables.
On Mon= day, July 18, 2022 at 6:40:36 PM UTC-7 Richard Huntsinger wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 0.8ex;border-left:1p= x solid rgb(204,204,204);padding-left:1ex">Thank you much, fiddlosopher, fo= r your quick reply.=C2=A0 Clearly, I need make use of lua filters to adjust= for the HTML code in my Jupyter notebooks.=C2=A0 I've now read the lua= documentation and tried some of the examples on the pandoc doc site and pa= ndoc/lua-filters repository - but I don't see an example of how to sear= ch for and transform HTML-format tables to native pandoc-format tables, or = similar such thing.=C2=A0 Can you provide me some additional guidance?=C2= =A0 =C2=A0

On Monday, July 18, 2022 at 12:54:17 AM UTC-7 fiddlosopher wrote:<= br>
Raw HTML in a Markdown= document (which is apparently what the R display_html function produces) w= ill 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 blo= cks and uses pandoc.read to convert them to native pandoc tables, which cou= ld then be rendered in PDF. I believe there are examples of such filters e= ither in the Lua filters documentation, or in the pandoc/lua-filters reposi= tory, 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 &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
------=_Part_539_629597917.1658435368655-- ------=_Part_538_89730427.1658435368655--