pandoc
pandoc copied to clipboard
Add support for alt text as short title in latex
Use the images ~~alt text~~ title as a short caption for the list of figures in latex documents.

Should now result in:
\caption[Voyage to the moon]{la lune}
in latex figures.
Nice catch @waeltken !
I think we need to update the documentation of the Images -> implicit_figures section in the readme.
Let's see what @jgm first think about this feature.
And maybe a test should ne nice too.
Yep, i just saw that the test for the basic writer fails, so that's not good.
diff --git a/tests/writer.latex b/tests/writer.latex
index 506c21d..0f29353 100644
--- a/tests/writer.latex
+++ b/tests/writer.latex
@@ -938,7 +938,7 @@ From ``Voyage dans la Lune'' by Georges Melies (1902):
\begin{figure}[htbp]
\centering
\includegraphics{lalune.jpg}
-\caption{lalune}
+\caption[Voyage dans la Lune]{lalune}
\end{figure}
Here is a movie \includegraphics{movie.jpg} icon.
That should do the job for the test.
Seems reasonable! Thanks! :wink:
Well this actually works really nice for my thesis! So even if this get's rejected I am still very happy. :smile:
+1
I have an issue with pandoc-crossref which I use for my thesis. This patch does not work with this plugin. See :
{#fig:figure-label}
produces
\begin{figure}[htbp]
\centering
\includegraphics{figure.png}
\caption[]{\label{fig:figure-label}My long caption}
\end{figure}
Instead of :
\begin{figure}[htbp]
\centering
\includegraphics{figure.png}
\caption[Short caption]{\label{fig:figure-label}My long caption}
\end{figure}
Looks like text short is empty after the plugin pandoc-crossref.
Any idea ?
Seems to be a pandoc-crossref related issue : https://github.com/lierdakil/pandoc-crossref/issues/38
@waeltken Could you please apply this patch instead :
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 0caa807..cbd6bd8 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -353,11 +353,14 @@ blockToLaTeX (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
inNote <- gets stInNote
capt <- inlineListToLaTeX txt
img <- inlineToLaTeX (Image txt (src,tit))
+ short <- stringToLaTeX TextString tit
return $ if inNote
-- can't have figures in notes
then "\\begin{center}" $$ img $+$ capt $$ "\\end{center}"
else "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
- ("\\caption" <> braces capt) $$ "\\end{figure}"
+ if null short
+ then ("\\caption" <> braces capt) $$ "\\end{figure}"
+ else ("\\caption" <> brackets (text short) <> braces capt) $$ "\\end{figure}"
-- . . . indicates pause in beamer slides
blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
beamer <- writerBeamer `fmap` gets stOptions
It removes the [] if there is no alternative text in the image. Seems cleaner to me.
Thank you !
I think it’s okay now, right?
Am 12.10.2015 um 14:36 schrieb Hadrien Mary [email protected]:
Thank you, but I have updated the code since I did a mistake with $$ "\end{figure}"
— Reply to this email directly or view it on GitHub https://github.com/jgm/pandoc/pull/2447#issuecomment-147383831.
Yup
A small issue I have. Text inside short caption are not rendered. For example ") does not render short caption in italic.
You are right, that should definitely work. What's your resulting output?
I assume that this line here:
short <- stringToLaTeX TextString tit
does not produce the required markup. But I don't know how to parse that part of the title correctly at the moment. I guess our maintainer John might know. :wink: I'll look in to it later this week.
You could try:
short <- stringToLaTeX CodeString tit
But right now i simply don't have the time and need for italics etc. in the short caption.
I think the travis test fails because the patch is not applied to the master branch but the latest release version. I've done a rebase to the master branch, but i don't know how github handles this if i do a force push on that branch now. Will it keep the references to the related commits when the commit hash changes?
I don't know why travis is failing. Rebase is often needed before merging to master. And yes the commit history will be kept. Let's wait for @jgm to comment on the PR and handle travis stuff !
+++ waeltken [Oct 13 15 05:16 ]:
I assume that this line here: short <- stringToLaTeX TextString tit
does not produce the required markup. But I don't know how to parse that part of the title correctly at the moment. I guess our maintainer John might know. :wink: I'll look in to it later today or this week.
That just does escaping that's needed for plain string
content in LaTeX (e.g. \% for %). It doesn't parse
as Markdown.
Note that in Markdown images

the "alt" part is the alt text and the "title" part is the title. The "alt" part does get parsed as Markdown, but the "title" part is just a plain string.
Note that in Markdown images
the "alt" part is the alt text and the "title" part is the title. The "alt" part does get parsed as Markdown, but the "title" part is just a plain string.
@hadim: So this would mean that we can not have markup e.g. italics in the title here then.
@jgm: So do you see this as a useful addition? I mean the semantics to use the markdown title as a title for the list of figures in latex does not seem wrong to me. Of course the current version of pandoc does not support a list of figures, but people employing a specialized template might use it.
@hadim wrote:
I don't know why travis is failing.
There was an internal server error on the appveyor ci server. So i pushed the branch again to trigger ci again.
It should pass now.
I guess we won't have markups in list of figures title... But I understand and I can live with that :-)
@jgm are you planning to merge this PR ?
+++ Hadrien Mary [Oct 14 15 05:55 ]:
[1]@jgm are you planning to merge this PR ?
I don't know, I haven't had time to think it through yet.
Just a small up so we don't forget this PR :-)
I'm not sold on this. Why is it needed? Can you give a realistic example?
Well since I get these emails, I'll chime in I guess. I used pandoc markdown for my phd thesis, and would have appreciated this feature. As it was, i had to go in by hand in the final version after converting it to latex & add alt captions to all the images so that the figure list up front with the TOC had reasonable one-line names in it, but figures in the body of the document could be captioned with a more descriptive two or three sentences.
On Thu, Dec 3, 2015, 10:41 AM John MacFarlane [email protected] wrote:
I'm not sold on this. Why is it needed? Can you give a realistic example?
— Reply to this email directly or view it on GitHub https://github.com/jgm/pandoc/pull/2447#issuecomment-161742789.
.. typed on a tiny virtual keyboard .. the usual requests for generosity in reading
Well I use it to have different caption below the figures and in the \listoffigures section. For example for my phd thesis I use a lot of figures with very long caption and I don't want to display all the captions in \listoffigures. This is why I use short title mechanism to be able to display only a short sentence summarizing the figure.
If you're against this feature, just tell me and I will maintain a patch for each new pandoc version.
Thank you for your time anyway :-)
OK, I see the point.
My only reservation is that it might seem surprising to overload the title in this way. Lots of people may use a blank title, or they may want the title to have something else, and it may be unexpected/break existing workflows to have it become the short title.
What about making the first sentence of the caption into the short title? Would that work or would it still be too long?
Another possibility would be to look for a span with class "short-caption" inside the caption; if found, it could be used as the short caption.
Example:

Thoughts?
+++ Hadrien Mary [Dec 03 15 10:49 ]:
Well I use it to have different caption below the figures and in the \listoffigures section. For example for my phd thesis I use a lot of figures with very long caption and I don't want to display all the captions in \listoffigures. This is why I use short title mechanism to be able to display only a short sentence summarizing the figure.
If you're against this feature, just tell it and will maintain a patch for each new pandoc version.
Thank you for your time anyway :-)
— Reply to this email directly or [1]view it on GitHub.
References
- https://github.com/jgm/pandoc/pull/2447#issuecomment-161744773
Well I don't have any specific preferences about this. I am ok as I can specify a short caption :-)
Maybe we should ask to @el-ee and @waeltken .