Document Classesproblem redefining caption in document class

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
dinofizz
Posts: 3
Joined: Thu Oct 16, 2008 10:13 pm

problem redefining caption in document class

Post by dinofizz »

Hello

I have a document class provided by my school which redefines caption. My document builds fine with 0 errors or warnings, but in my output there always appears the word "figure" below the caption of figures and the word "table" above tables. If I comment out the caption redefine in the document class file the problem disappears. Can anyone explain why this is happening? I notice no other effect of removing the redefine, but as I am not too familiar with the latex syntax I'm not exactly sure what it is actually doing, or why it has been redefined.

Caption redefine in document class:

Code: Select all

Code, edit and compile here:
\long\def\@caption#1[#2]#3{\par\addcontentsline{\csname ext@#1\endcsname}{#1}{%
\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}
\begingroup \@parboxrestore \normalsize
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}{#1}\par
\endgroup}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Extra info:

I am using png and pdf images.

Previously I used MikTex + TexnicCentre, and after switching to Linux I am now using Texlive + Kile. This problem did not appear when I was using Windows.

Thanks
Dino

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

problem redefining caption in document class

Post by Stefan Kottwitz »

Hi Dino,

welcome to the board!
Does this class redefine \@makecaption? To be able to help we would need the code of this class.
Using a standard class I would remove {#1} after \@makecaption:

Code: Select all

Code, edit and compile here:
\long\def\@caption#1[#2]#3{\par\addcontentsline{\csname ext@#1\endcsname}{#1}{%
\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}
\begingroup \@parboxrestore \normalsize
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
\endgroup}
\makeatother
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Stefan
LaTeX.org admin
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

problem redefining caption in document class

Post by sommerfee »

The problem lies in this bit of code:
dinofizz wrote:

Code: Select all

...
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}{#1}\par
...
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
\@makecaption has usually two arguments. But this definition of \@caption call it with three arguments, so I assume that it is defined with three arguments within your document class. In my eyes this is a really really very very bad idea since several packages redefines \@caption (and assume that \@makecaption must be called with two arguments), and some packages redefines \@makecaption (with two arguments). But this would cause an extra {#1} while #1 is either "figure" or "table". Beside this many packages (e.g. the listings package) are using \@makecaption within their code. So this definition of \@caption and \@makecaption is to draw incompatibilities like moths to the flame.

If this has worked before, and now it isn't working, then I assume that you use a LaTeX package which hasn't redefined \@caption before, but is now doing so in its current version. Or a package redefines \@caption in a different way than its predecessors. Or it is redefining \@makecaption. Without having a small but complete document showing the problem this is hard to tell.

HTH,
Axel
Last edited by sommerfee on Fri Oct 17, 2008 7:23 am, edited 1 time in total.
dinofizz
Posts: 3
Joined: Thu Oct 16, 2008 10:13 pm

Re: problem redefining caption in document class

Post by dinofizz »

Thank you so much for your reply, it definitely helps in the understanding of the problem.

I don't know how how enthusiastic you are about solving this problem, if you are indeed interested I will gladly post more w.r.t. an example document and the document class file which redefines several items such as the caption and figure handling, etc.

For now I think I will work with the workaround, and should further problems arise, handle them accordingly. This will also give me a chance to investigate how Latex works.

Thanks again.
Dino
dinofizz
Posts: 3
Joined: Thu Oct 16, 2008 10:13 pm

problem redefining caption in document class

Post by dinofizz »

On reflection, while I have some time now it might be best to see how this is working. The makecaption function is indeed redefined as such:

Code: Select all

Code, edit and compile here:
\def\tablestring{table}
\def\figurestring{figure}
\newlength{\captionindent}
\long\def\@makecaption#1#2#3{
\ifx\figurestring#3
\vskip 5pt
\setbox\@tempboxa\hbox{#1~:~#2}
\ifdim \wd\@tempboxa >\hsize
\setbox\@tempboxa\hbox{#1~:~}
\setlength\captionindent{\wd\@tempboxa} \divide\captionindent by 1
\parbox[t]{\hsize}{\hangindent \captionindent \hangafter=1%
\unhbox\@tempboxa#2}
\else \hbox to\hsize{\hfil\box\@tempboxa\hfil}
\fi
\else % for a table
\vskip 5pt
\setbox\@tempboxa\hbox{#1~:~#2}
\ifdim \wd\@tempboxa >\hsize
\setbox\@tempboxa\hbox{#1~:~}
\setlength\captionindent{\wd\@tempboxa} \divide\captionindent by 1
\parbox[t]{\hsize}{\hangindent \captionindent \hangafter=1%
\unhbox\@tempboxa#2}
\else \hbox to\hsize{\hfil\box\@tempboxa\hfil}
\fi
\vskip 8pt
\fi}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Off-topic:
I cannot believe I spent my undergrad years working without Latex!! Magnitudes of scale better than MS Word hehe (regardless of these small issues).

Thanks again for all your replies.
Dino
Post Reply