I'd check out if there's an extension flag (https://pandoc.org/MANUAL.html#extensions) you can add to commonmark_x input for it to process multiline attributes. Or one that can be added to markdown to process math attributes.

As the Pandoc AST doesn't have attributes on Math elements (https://pandoc.org/lua-filters.html#type-math) the common mark reader turns them into attributes of a container Span element, as your output shows. So an alternative would be to simply write the span in Pandoc's markdown by simply adding a backtick before and after:

`$$x = 1+2$$`{ .cs #math:equation caption=test}

`$x = 1+2$ `{ .cs #math:equation caption=test}

~~~{
  .cs
  #lst:my-listing
  caption=test }
def f(x):
   return x
~~~

Writing a Lua filter that picks up either is also an option. Picking up attributes list after equations is probably a bit complicated. But using pattern matching to process the initial {...} in a code block is more feasible.

All the best,

On Wednesday, February 22, 2023 at 8:15:53 AM UTC A A wrote:
Anyone? I also opened an issue in Github but no response.

On Fri, 17 Feb 2023 at 12:01, A A <amine.ab...@gmail.com> wrote:
Dear all,

Having not received a response to my query below, I ran a few of my own tests to try to understand what is going on.

It seems that commonmark_x does recognize attributes for both inline and display math. If I have the following in my markdown file:

$$x = 1+2$${ .cs #math:equation caption=test}

$x = 1+2${ .cs #math:equation caption=test}

~~~{
  .cs 
  #lst:my-listing 
  caption=test
  }
def f(x):
    return x
~~~

And I run pandoc --from commonmark_x --to native test.md I will get the following:

[ Para
    [ Span
        ( "math:equation" , [ "cs" ] , [ ( "caption" , "test" ) ] )
        [ Math DisplayMath "x = 1+2" ]
    ]
, Para
    [ Span
        ( "math:equation" , [ "cs" ] , [ ( "caption" , "test" ) ] )
        [ Math InlineMath "x = 1+2" ]
    ]
, CodeBlock
    ( "" , [ "{" ] , [] )
    "  .cs \n  #lst:my-listing \n  caption=test\n  }\ndef f(x):\n    return x"
]

Notice that the multiline attributes for the CodeBlock element are not picked up. If I instead try pandoc --from markdown --to native test.md:

[ Para
    [ Math DisplayMath "x = 1+2"
    , Str "{"
    , Space
    , Str ".cs"
    , Space
    , Str "#math:equation"
    , Space
    , Str "caption=test}"
    ]
, Para
    [ Math InlineMath "x = 1+2"
    , Str "{"
    , Space
    , Str ".cs"
    , Space
    , Str "#math:equation"
    , Space
    , Str "caption=test}"
    ]
, CodeBlock
    ( "lst:my-listing" , [ "cs" ] , [ ( "caption" , "test" ) ] )
    "def f(x):\n    return x"
]

The attributes in the CodeBlock element are picked up, but the attributes for display and inline math are not.

Unfortunately, for my use case I would like to be able to assign multiline attributes to code block elements and assign attributes to display and inline math elements.

Is there a way to achieve both in the same markdown file? Thanks for your consideration.

Regards,

Amine


---------- Forwarded message ---------
From: A A <amine.ab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Wed, 8 Feb 2023 at 13:52
Subject: Can math elements have attributes
To: <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


Dear all,

I am writing my own pandoc to latex converter using panflute and would like to attach attributes to Math elements. I have tried the following syntax, but it seems that the attribute is not being picked up by panflute:

```
$$x=y$${ a=b }
```

I did some of my own research to figure out what I was doing wrong. And a couple of things became apparent:

- On the one hand, it looks like pandoc might not support this:
- On the other hand, `pandoc-crossref` seems to be able to handle this syntax:

Is this currently supported by pandoc? If not then how is `pandoc-crossref` able to handle it? Thanks for your consideration.

Regards,

Amine


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/0845b275-aa43-4fc3-86a5-17b20de652een%40googlegroups.com.