public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* LaTeX reader: Issue when `\label` and `\caption` separated
@ 2022-12-28 16:22 Ash Wiseth
  0 siblings, 0 replies; only message in thread
From: Ash Wiseth @ 2022-12-28 16:22 UTC (permalink / raw)
  To: pandoc-discuss


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

Hi,

I use to Pandoc to convert a large number of LaTeX articles into Markdown, 
with the original LaTeX articles all from different authors with their own 
idiosyncratic styles. I've been trying to narrow down some of the 
conversion issues that have cropped up, and I noticed that the LaTeX reader 
seems to be very particular about how elements in float (table, figure) 
environments are ordered.

For LaTeX, `\label` normally has to be either inside `\caption` or after 
`\caption`. As far as I know, however, there is no requirement that 
`\label` (if appearing after and not inside) appear *immediately* after 
`\caption`. For example, I can get the following (with `\label` *not* immediately 
after `\caption`) to compile without any errors or warnings:

```
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\begin{document}

\section{Introduction}

 The model is shown in Figure \ref{fig:sensPlot}.

    \begin{figure}
        \caption{Dependence on Prior Settings}
        \includegraphics[width=0.7\textwidth]{figures/sensPlot-1.pdf}
        \label{fig:sensPlot}
    \end{figure}

\end{document}
```

However, when I run Pandoc 2.19.2 to convert this to Markdown, the figure 
is not processed correctly (the cross-reference appears as [fig:sensPlot] 
instead of 1, and the caption disappears):

```
# Introduction

The model is shown in Figure 
[\[fig:sensPlot\]](#fig:sensPlot){reference-type="ref" 
reference="fig:sensPlot"}.

![image](figures/sensPlot-1.pdf){width="70%"} []{#fig:sensPlot 
label="fig:sensPlot"}
```

Running `pandoc -t native`, it looks like the label is getting separated 
from the rest of the figure:

```
[ Header
    1 ( "introduction" , [] , [] ) [ Str "Introduction" ]
, Para
    [ Str "The"
    , Space
    , Str "model"
    , Space
    , Str "is"
    , Space
    , Str "shown"
    , Space
    , Str "in"
    , Space
    , Str "Figure"
    , Space
    , Link
        ( ""
        , []
        , [ ( "reference-type" , "ref" )
          , ( "reference" , "fig:sensPlot" )
          ]
        )
        [ Str "[fig:sensPlot]" ]
        ( "#fig:sensPlot" , "" )
    , Str "."
    ]
, Para
    [ Image
        ( "" , [] , [ ( "width" , "70%" ) ] )
        [ Str "image" ]
        ( "figures/sensPlot-1.pdf" , "" )
    , SoftBreak
    , Span
        ( "fig:sensPlot" , [] , [ ( "label" , "fig:sensPlot" ) ] )
        []
    ]
]
```

Note that this can be fixed by (1) moving `\label` into `\caption`, (2) 
switching `\includegraphics` and `\label`, or (3) switching `\caption` and 
`\includegraphics`. So it definitely seems like an order issue.

What am I missing? Is this a bug?

Thank you in advance.

-- 
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/b31d021f-ce8b-4c2e-b2bd-ad9d65a68606n%40googlegroups.com.

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-28 16:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 16:22 LaTeX reader: Issue when `\label` and `\caption` separated Ash Wiseth

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).