public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Thomas Hodgson <thomas.hodgson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Lua filter process LaTeX
Date: Mon, 26 Oct 2020 04:44:49 -0700 (PDT)	[thread overview]
Message-ID: <59cbbd11-ca9d-4334-a348-92277bb459c2n@googlegroups.com> (raw)
In-Reply-To: <021778da-effc-47ab-b69b-1d33e16a041fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


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

I think that the regex was partly the problem. This does what I want, as 
long as there is a line break after the end of the `\caption`. The errors I 
was getting from pandoc.read were because the input wasn't good LaTeX.

```
local caption = string.match(el.text, "\\caption{(.+)}\n")
        if caption then
            local alt_text = pandoc.utils.stringify(pandoc.read(caption, 
'latex').blocks)
            return pandoc.Plain({pandoc.Image({pandoc.Str(alt_text)}, 
fname)})
```

On Monday, 26 October 2020 at 11:28:24 UTC+1 Thomas Hodgson wrote:

> I have been learning how to write filters with Lua. I started with the 
> tikz.lua example, and changed it to search for any figure. I want to put 
> captions in the alt text of the images. So, I added this:
>
> ```
> local caption = string.match(el.text, "\\caption{(.-)}")
>         if caption then
>             return pandoc.Plain({pandoc.Image({pandoc.Str(caption)}, 
> fname)})
> ```
>
> That works, but it turns the raw LaTeX into a string, and my regex only 
> goes as far as the last bracket; this is a regex issue.. So, I get things 
> like this as alt text:
>
> `foo' \emph{bar
>
> Is there a way to have the filter turn that LaTeX into Pandoc's native 
> format? I tried to think about pandoc.read, but didn't get very far.
>
> Thanks.
>
> Tom
>

-- 
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/59cbbd11-ca9d-4334-a348-92277bb459c2n%40googlegroups.com.

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

  parent reply	other threads:[~2020-10-26 11:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 10:28 Thomas Hodgson
     [not found] ` <021778da-effc-47ab-b69b-1d33e16a041fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-26 11:44   ` Thomas Hodgson [this message]
     [not found]     ` <59cbbd11-ca9d-4334-a348-92277bb459c2n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-26 12:41       ` William Lupton
     [not found]         ` <CAEe_xxi3KVqos4O4Q4Ng1vx=WB9wT8dV+-z1DMq7FsxGVRkF3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-10-26 15:52           ` Thomas Hodgson
     [not found]             ` <09ac0613-ca74-459f-8cd1-e09c276308dbn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-30 10:32               ` Thomas Hodgson
     [not found]                 ` <ca58cb60-eda3-4ae0-86b6-b6c27aba7c3bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-30 16:11                   ` Albert Krewinkel
     [not found]                     ` <87pn4zlmna.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2020-11-20 22:21                       ` Thomas Hodgson

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=59cbbd11-ca9d-4334-a348-92277bb459c2n@googlegroups.com \
    --to=thomas.hodgson-re5jqeeqqe8avxtiumwx3w@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).