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

captions on figures in margins #998

Closed
teepeemm opened this issue May 19, 2018 · 3 comments
Closed

captions on figures in margins #998

teepeemm opened this issue May 19, 2018 · 3 comments

Comments

@teepeemm
Copy link
Contributor

I'm wanting to place images with captions in my margins. I've been doing this using the caption package and the captionof command, as in the following:

\documentclass{article}
\usepackage{caption}
% if we want to remove the caption package:
\providecommand{\captionsetup}[1]{}
\providecommand{\captionof}[2]{\caption{#2}}

\begin{document}

% orphans
\captionof{figure}{An orphan captionof is ok}
\captionsetup{type=figure}
\caption{An orphan figure: Error: outside of float}

% marginpars
\marginpar{
\captionof{figure}{marginpar with captionof: Error: figure isn't allowed in note}
}
\marginpar{
\captionsetup{type=figure}
\caption{marginpar with caption: Error: outside of float}
}

% parbox
\parbox{\textwidth}{
\captionof{figure}{parbox with captionof is ok}
}
\parbox{\textwidth}{
\captionsetup{type=figure}
\caption{parbox with caption: Error: outside of float}
}

% figure
\begin{figure}[t]
\caption{figure with caption ok}
\end{figure}

\end{document}

Unfortunately, this approach is not translating over to LaTeXML correctly. Each of the uses of caption outside of the float is accompanied by an error (three "unexpected captions" and one "malformed ltx:figure". If I remove the caption package (and ignore the commands it defines), then LaTeX also complains about these four, saying "caption outside float" (and the other two that needed the package as well, of course).

It seems that we try to make this approach possible. In caption.sty.ltxml, the captionof macro has the comment:

# This is a horrible thing that fakes a caption anywhere.
# It isn't necessarily IN a figure or any float, so we'll wrap it in an otherwise empty one!

This seems to work out ok in two of the cases (the orphan and the parbox), but not in the marginpar. And captionsetup doesn't seem to work in any of the three cases. Is there a way I can get captions in my margins?

@dginev dginev added this to the LaTeXML-0.8.4 milestone May 19, 2018
@brucemiller
Copy link
Owner

Interesting problem! Seems there's several ways this might be dealt with. One would be to extend the model of ltx:note to allow para-level stuff (eg. figures), but since it's so overloaded to store general textual metadata (footnotes, marginpars, etc), it might want 2 variants for inline-level and para-level. Could get messy.

But then, you're not really wanting the figure in the margin, just the caption. I'd be tempted to stick with the more logical markup of having the caption be part of the figure, but use CSS to show it in the margin. So define, maybe \margincaption differently for latexml & latex (either with a style file with ltxml binding, or just use \iflatexml conditional). The latexml version would simply use \caption (but add a css file), and the latex version would put a \captionof inside a marginpar.

Does that sound workable?

@teepeemm
Copy link
Contributor Author

Unfortunately, I'm doing [images with captions] in my margin, not images with [captions in my margin] --- they're staying together, but both end up in the margin.

But I do suppose a workaround would be to use CSS to move both to the margin. I'll ponder that.

@brucemiller
Copy link
Owner

Ah, sorry, I misunderstood. So, I guess the best thing is to let marginpar accept a broader (para-level) part of the schema. And also fix \captionsetup to note that you're pretending to be in a figure (or whatever). So, your example runs without error now, but still creates a "note". By default that acts like a footnote with mouseover popup, but it has class ltx_note ltx_role_margin, so you'd still need to use some CSS to put it in the "margin" --- whatever you decide the "margin" means! :>

Thanks for the report!

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

3 participants