2

I'm generating LaTex automagically from a lengthy document that is written in the multimarkdown language, compiled by a software package called Scrivener. It's a workflow that works well, but this is one of the issues I'm hitting. I don't want to have to replace / delete numerous caption command each time I compile to LaTex.

The MWE below illustrates the issue.

This remove Figure n: and caption from included graphic. However, it leaves a blank line, which makes the images spacing appear gauche. Is there a simple way to remove the blank line , without inserting space adjustments, each time a figure is used Thanks.

\documentclass{memoir}

\usepackage{mwe}                    %   for dummy images
\usepackage[labelformat=empty]{caption} %   remove figure captions

\begin{document}

 \begin{figure}[!ht]
  \centering
  \includegraphics[width=0.5\textwidth]{image}                   
  \caption{}
  \end{figure}
   This is first text after caption.

\end{document}
15
  • 1
    Don't write \caption{}..?
    – jon
    Apr 10, 2014 at 17:19
  • @jon see my edited explanation of how my workflow creates this issue
    – johnbrc
    Apr 10, 2014 at 17:23
  • Will any figures need a caption? If not, isn't it easy to do something like \let\caption\relax? (Probably need to do that after \usepackage{caption}.) Note: I don't know if Scrivener allows you to define arbitrary commands or not, or fiddle with the preamble...
    – jon
    Apr 10, 2014 at 17:24
  • Thanks. I don't envisage any figures requiring a caption, no. I tried \let\caption\relax in the preamble, but that returns error: \caption undefined
    – johnbrc
    Apr 10, 2014 at 17:28
  • Are you always putting \includegraphics[..]{...} \caption{..}? If so, one can use this "pattern" to perform certain replacements. Do you sometimes use \caption with a non-empty argument?
    – Werner
    Apr 10, 2014 at 17:37

2 Answers 2

2

memoir provides its own interface for caption management, and there may be some clashes when using it in conjunction with caption (see section 10.13 The class versus the caption package (and its friends), p 206 of the memoir user manual).

However, you can update \caption to grab its contents, evaluate whether the argument is empty/not, and condition accordingly:

enter image description here

\documentclass{memoir}

\usepackage{mwe}                    %   for dummy images
\usepackage[labelformat=empty]{caption} %   remove figure captions

% http://tex.stackexchange.com/a/58638/5764
\makeatletter
\def\ifemptyarg#1{%
  \if\relax\detokenize{#1}\relax % H. Oberdiek
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother

\let\oldcaption\caption
\AtBeginDocument{%
  \renewcommand{\caption}[2][]{%
    \ifemptyarg{#2}{}{\oldcaption[#1]{#2}}%
  }%
}

\begin{document}

\begin{figure}[!ht]
  \centering
  \includegraphics[width=0.5\textwidth]{image}                   
  \caption{}
\end{figure}
This is first text after caption.

\newpage

\begin{figure}[!ht]
  \centering
  \includegraphics[width=0.5\textwidth]{image}                   
  \caption{Some caption}
\end{figure}
This is first text after caption.

\end{document}

If you're not using the optional argument of \caption in your workflow, then the redefinition could be a bit simpler:

\AtBeginDocument{%
  \renewcommand{\caption}[1]{%
    \ifemptyarg{#1}{}{\oldcaption{#1}}%
  }%
}
0
1

If you really don't use captions anywhere, redefine \caption to do nothing.

\renewcommand{\caption}{}

Which I think will do what you want.

4
  • that looks promising…will test on whole document before upmarking
    – johnbrc
    Apr 10, 2014 at 17:31
  • @johnbrc -- If you are getting \caption undefined with my suggestions, you won't be able to \renewcommand it either since there is no command (yet) to REnew.
    – jon
    Apr 10, 2014 at 17:33
  • This works on the MWE…but not on my document. Is that what your comment @jon implies I should expect?
    – johnbrc
    Apr 10, 2014 at 17:48
  • Try the renewcommand right before begin document?
    – bombcar
    Apr 10, 2014 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .