Closed jcoulombe closed 13 years ago
This one I have to think about. The idea of a caption is simply to have some basic text, not anything too complicated. Remember, it derives from the title attribute in HTML images, which I don't believe allow anything other than plain text.
To actually parse the code inside the caption would require a rather complicated change that I can almost guarantee won't happen.
Then, I'm left with the fact that I have to escape it, or I'll get all sorts of bug complaints about crashing XHTML or LaTeX because of special characters being unescaped inside the caption.
I'm leaning towards declaring this one "out of bounds" and suggesting that it's a good place to use hand-crafted HTML or LaTeX.
One possible exception - IF (and that's potentially a big IF) there was a way to pass a single \input{file} through the caption so that you could include that stuff in an external file for LaTeX, would that solve the issue? I don't foresee this being an XHTML problem, purely a LaTeX issue. (Which brings up the point that if something is too output specific (e.g. LaTeX only, and not XHTML), it might not belong in MMD.
This might be better handled by a post-processing script that looks for $\backslash$input{file} inside a caption, and changes it out for valid latex code (if you can use \input inside of caption.
I tried manually setting the caption of an image to:
\caption{\input{file}}
and then creating file.tex with the contents of what went into the caption,including an \autoref.
It gave an error during the latexmk about an extra }, but by hitting return a few times it processed it and generated the proper result.
So it seems like this should work, and might be a valid alternative. I just don't think this is going to make it in as a core feature of MMD 3. But you can easily create a script to run on the tex file to reformat:
$\backslash$input{file}
into:
\input{file}
F-
Actually, here is the situation for me:
If I cannot use mmd inside captions, my preferred solution is to allow plain latex there. So I found a set of pre- and post-substitutions that seem to work okay for that.
The side effect is that plain latex is allowed in the whole document.
I'll see in the long run how that works...
I'm just afraid that this is going to be too specific of a situation to create an entire workaround for.
Nothing is set in stone, and I'm always open to convincing arguments... ;)
This might also be a good opportunity for a fork if you wanted to add this feature. It would be an easy change to always put raw text into the caption. Basically, you should be able to change:
g_string_append_printf(out, "\\caption{");
print_latex_string(out, elt->contents.link->title);
g_string_append_printf(out, "}\n");
to
g_string_append_printf(out, "\\caption{%s}\n", elt->contents.link->title);
This will change all citations to use raw text, so you have to be careful about special characters.
Captions are not parsed using mmd syntax, while any special character is escaped. As a result, the final caption always prints literally the raw content of the MMD source. Therefore it seems impossible to put any formatting and, more importantly, links in captions.