Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't output \caption in LaTeX when image alt text is empty #2844

Closed
Adri2000 opened this issue Apr 6, 2016 · 8 comments
Closed

Don't output \caption in LaTeX when image alt text is empty #2844

Adri2000 opened this issue Apr 6, 2016 · 8 comments

Comments

@Adri2000
Copy link

Adri2000 commented Apr 6, 2016

Tested with .md as input, LaTeX/Beamer as output.
![](image.png) will generate \caption{}.

This is a regression according to https://groups.google.com/forum/#!topic/pandoc-discuss/9H_3h20ILj0. Maybe in commit d81b435.

Proposed patch on master:

diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 9526333..4fac59a 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -417,7 +417,9 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = d
   img <- inlineToLaTeX (Image attr txt (src,tit))
   let footnotes = notesToLaTeX notes
   lab <- labelFor ident
-  let caption = "\\caption" <> captForLof <> braces capt <> lab
+  let caption = if null text
+                   then empty
+                   else "\\caption" <> captForLof <> braces capt <> lab
   figure <- hypertarget ident (cr <>
             "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
             caption $$ "\\end{figure}" <> cr)

Not tested, but I successfully tested a similar patch for the pandoc version that's running on my laptop.

@jgm
Copy link
Owner

jgm commented Apr 10, 2016

The change you suggest would mean that uncaptioned images don't get labels, even if an ID is specified.

@Adri2000
Copy link
Author

Sorry, not sure I understand exactly what you mean. Do you have an example?

@jgm
Copy link
Owner

jgm commented Apr 19, 2016

![](img.jpg){#myimage}

With the proposed change, you won't get \label{myimage} anywhere in the figure.

@Adri2000
Copy link
Author

Does the following look better? If not please don't hesitate to just fix it and commit, as I'm really not familiar with Haskell, and not much with Pandoc either :)

Thanks!

diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 9526333..683d737 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -417,7 +417,9 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = d
   img <- inlineToLaTeX (Image attr txt (src,tit))
   let footnotes = notesToLaTeX notes
   lab <- labelFor ident
-  let caption = "\\caption" <> captForLof <> braces capt <> lab
+  let caption = if null text
+                   then lab
+                   else "\\caption" <> captForLof <> braces capt <> lab
   figure <- hypertarget ident (cr <>
             "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
             caption $$ "\\end{figure}" <> cr)

@jgm
Copy link
Owner

jgm commented Apr 20, 2016

On reflection, I guess that without \caption, it probably
doesn't make sense to have \label, since there will be no
figure number to refer to.

But that raises the question what behavior would be better.
Some might expect that a figure with empty caption would
still get a figure number and be labelable.

+++ Adrien Cunin [Apr 20 16 06:28 ]:

Does the following look better? If not please don't hesitate to just
fix it and commit, as I'm really not familiar with Haskell, and not
much with Pandoc either :)

Thanks!
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 9526333..683d737 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -417,7 +417,9 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i
':'g':':':tit)]) = d
img <- inlineToLaTeX (Image attr txt (src,tit))
let footnotes = notesToLaTeX notes
lab <- labelFor ident

  • let caption = "\caption" <> captForLof <> braces capt <> lab

  • let caption = if null text

  •               then lab
    
  •               else "\\caption" <> captForLof <> braces capt <> lab
    

    figure <- hypertarget ident (cr <>
    "\begin{figure}[htbp]" $$ "\centering" $$ img $$
    caption $$ "\end{figure}" <> cr)


    You are receiving this because you commented.
    Reply to this email directly or [1]view it on GitHub

References

  1. Don't output \caption in LaTeX when image alt text is empty #2844 (comment)

@Adri2000
Copy link
Author

Hi,
What's the best way to move forward on this issue?

@jgm jgm added this to the pandoc 2.0 milestone Mar 5, 2017
@jgm jgm closed this as completed in 7d9d77c Jun 27, 2017
@jgm
Copy link
Owner

jgm commented Jun 27, 2017

Fixing this by requiring a non-empty caption for implicit_figures.

@jgm
Copy link
Owner

jgm commented Jun 27, 2017

Note: you'll now get no figure at all (not just a figure without a \caption) if you have empty alt text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants