-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
[feature] Ability to remove the caption from pdf output #37
Comments
This is because I don't have much free time these days to add the option to change this. Would you be able to make a pull request? Otherwise, I'll get around to it when I get some time |
I can confirm this has nothing to do with pandoc-plot, because if you transform the same document with
you will see that nothing except for an image element has been added. The Spent quite some time on the very same issue. Strangely, Pandoc does not generate the captions for images that use a Data URL, like those from the Mermaid filter for Pandoc. |
@samuel-emrys I'm hesitant to remove the figure numbering for empty captions because of backwards compatibility. However, here's an example for a small Python filter you can use to transform figures generated from pandoc-plot which have empty captions, into normal images. Input file: # title
paragraph
```{.matplotlib}
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,2,3,4])
``` Filter: # empty-captions.py
from pandocfilters import toJSONFilter, Image
def empty_captions(key, value, *_):
if key == 'Image':
attrs, caption, (url, title) = value
if not caption:
# pandoc considers the image to be a figure (with numbering)
# if the title starts with "fig:"
if title.startswith("fig:"):
title = title[4::]
return Image(attrs, [], (url, title))
if __name__ == "__main__":
toJSONFilter(empty_captions) Command: $ pandoc --filter pandoc-plot --filter empty-captions.py -i myfile.md -t latex Let me know if that is enough for you |
Thanks for that @LaurentRDC, this works great. As the maintainer, this is obviously your decision but I think that an option to toggle this would be well placed within pandoc-plot. Manipulating how figures are generated seems to be directly within the scope of such a filter. As far as backward compatibility goes, you could maintain compatibility with the current API by providing an optional argument that defaults to the current behaviour, but gives those that want to do this an option to turn the captions off. What are your thoughts? From a user perspective, I think this would be a lot cleaner. |
@samuel-emrys if you insist, I can add a parameter like If you want to do it yourself, I'm happy to review pull requests. Otherwise, I'll try to find time this week to do it |
I've just taken a quick look at the code base, and not being familiar with Haskell at all I think it would take me longer than a week to work out what I'm doing and where to inject the required changes unfortunately. Thanks a lot for your responsiveness though, I really appreciate it. |
I didn't want to increase complexity for the user with another parameter in the end. Following the latest commit (f24a95d), the figure numbering will disappear if the caption is empty or unspecified and there's no link to the script source. So this script: ```{.matplotlib caption="hello"}
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5], [1,2,3,4,5])
``` will result in the following LaTeX: \begin{figure}
\centering
\includegraphics{...}
\caption{hello}
\end{figure} but this script: ```{.matplotlib}
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5], [1,2,3,4,5])
``` will result in this: \includegraphics{plots/pandocplot6487719276475405948.png} I'll try to make a release today |
Release 1.5.1 contains this change. Give it a try and don't hesitate to reopen this issue if there's a problem |
See LaurentRDC#37. For whatever reason, the change introduced in the PR related to the issue above seems to not have an effect any more. Bring that change back. Seems we might have problems with pandoc-crossref and other filters because of which the change was dropped but right now this is the only filter we care about.
This behaviour has changed since v1.5.1 for recent pandoc version. With Input:
Result: \begin{figure}
\centering
\includegraphics{plots/pandocplot16601784956282164673.png}
\caption{hello}
\end{figure}
\begin{figure}
\centering
\includegraphics{plots/pandocplot16601784956282164673.png}
\caption{}
\end{figure} |
I found the problem, which arose when pandoc-types added the Do you need a new release for this? |
Thank you very much! Empty captions are omitted again since a125b56. |
See LaurentRDC#37. For whatever reason, the change introduced in the PR related to the issue above seems to not have an effect any more. Bring that change back. Seems we might have problems with pandoc-crossref and other filters because of which the change was dropped but right now this is the only filter we care about.
Is there a way to remove the caption from pdf output? When I try something similar to the following:
It renders the figure as follows:
This is compiled with:
I don't see a good way of being able to suppress the figure caption
The text was updated successfully, but these errors were encountered: