Graphics, Figures & Tablesrotating | Trouble with custom Package

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
NepaliKeto
Posts: 3
Joined: Sun Jul 01, 2012 7:13 pm

rotating | Trouble with custom Package

Post by NepaliKeto »

Hi,

I am writing a dissertation. I use graphicx package with pdftex option for figures (all PDFs). Everything was working fine until I added 'rotating' package to rotate some figures.

I get the following error when I compile the document with 'rotating' package enabled.

Code: Select all

! Extra }, or forgotten \endgroup.
\color@endbox -egroup
1.19 \end{figure}
Here's a minimal example that reproduces the error (also attached main.tex). The figure (cat.pdf) and style file (nmsudiss.sty) are attached. (Note: 'rotating' is not used in this example but I need it).

Any help is appreciated. Thanks

Code: Select all

\documentclass[12pt]{report}
\usepackage{nmsudiss} % Style file for dissertation
\usepackage[pdftex]{graphicx}
\usepackage{rotating}

\begin{document}

\begin{figure}[htbp]
\begin{center}
\mbox{
{\includegraphics[width=2in]{cat}}}
\caption{Cat}
\end{center}
\end{figure}

\end{document}
Attachments
Main.tex
Tex file
(291 Bytes) Downloaded 272 times
cat.pdf
Figure file
(2.96 KiB) Downloaded 245 times
nmsudiss.sty
Dissertation style file
(30.92 KiB) Downloaded 376 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

rotating | Trouble with custom Package

Post by cgnieder »

Hi,

The problem here is that nmsudiss redefines \@xfloat, originally provided by the LaTeX kernel. The reason for this is to restore the \baselinestretch to 1 again inside floats since the package sets it to 1.5 otherwise. Unfortunately the redefinition messes with rotating's internals.

A way to resolve the issue is to save the definition of \@xfloat before loading nmsudiss and restore the original definition again. This however leads to a wrong baselinestretch inside floats. That's why I patched \@xfloat again using etoolbox's \patchcmd.

This MWE runs without errors:

Code: Select all

\documentclass[12pt]{report}

% save \@xfloat
\makeatletter
\let\orig@xfloat\@xfloat
\makeatother
\usepackage{nmsudiss} % Style file for dissertation

% restore \@xfloat and reset baselinestretch in another way:
\usepackage{etoolbox}
\makeatletter
\let\@xfloat\orig@xfloat
\patchcmd{\@xfloat}{\columnwidth}{\columnwidth\def\baselinestretch{\@ne}}{}{}
\makeatother

% \usepackage{graphicx} % already loaded by `rotating' and detects the driver by itself
\usepackage{rotating}

\usepackage{mwe}% only for this example to provide dummy pictures!
\usepackage{lipsum}% only for this example to provide dummy text
\begin{document}
\lipsum[1]

\begin{figure}[htbp]
 \centering
 \includegraphics[width=2in]{example-image-a}
 \caption{Cat}
\end{figure}

\lipsum[2]

\end{document}
Regards
site moderator & package author
NepaliKeto
Posts: 3
Joined: Sun Jul 01, 2012 7:13 pm

rotating | Trouble with custom Package

Post by NepaliKeto »

Hi cgnieder,

Many many thanks. Your suggestion worked like a charm. :)

BTW, is there a way to change nmsudiss so that it does not mess with @xfloat, but gives the same \baselinestretch effected? Maybe, for example, by changing some codes in nmsudiss?

Thanks.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

rotating | Trouble with custom Package

Post by cgnieder »

It seems this package has been modified more than once:
  • Line 3 says %%% File: camdiss.sty, version 1.2, October 1994
  • Line 25 describes the usage: %%% \usepackage{utthesis}
  • it states UT Austin Thesis Style File but defines \newcommand{\@universityname}{New Mexico State University}
So I guess if you save the file under a different name (like mynmsuthesis.sty) there is nothing against it.

You should replace lines 846 (starting with \def\@xfloat#1[#2]{) to line 865 (ending with \hsize\columnwidth \@parboxrestore}) with these lines:

Code: Select all

\RequirePackage{etoolbox}
\patchcmd{\@xfloat}{\columnwidth}{\columnwidth\def\baselinestretch{\@ne}}{}{}
Regards
site moderator & package author
NepaliKeto
Posts: 3
Joined: Sun Jul 01, 2012 7:13 pm

rotating | Trouble with custom Package

Post by NepaliKeto »

That worked, thank you very much.

The original style file was created to work with Scientific Word 2.0. (UT Austin). It was modified for New Mexico State University and made to work with Latex. But that was long back. I guess no one ever used the rotating package to run into this problem.

Thanks
NepaliKeto
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

rotating | Trouble with custom Package

Post by cgnieder »

NepaliKeto wrote:The original style file was created to work with Scientific Word 2.0. (UT Austin). It was modified for New Mexico State University and made to work with Latex. But that was long back.
I thought something like this. My point is: it has not been properly maintained/modified which means it contains wrong and contradicting information. But I guess that's not going to change soon... after all, it would need someone with LaTeX knowledge from the university who feels responsible for maintaining the official thesis class... :)

Best regards
site moderator & package author
Post Reply