LyXSome help tweaking the amsbook class?

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
trogdor
Posts: 6
Joined: Wed Jul 16, 2008 4:28 pm

Some help tweaking the amsbook class?

Post by trogdor »

Greetings,

I'm using book (AMS) to transcribe a book, and would like to make a few modifications to get the style of output I'm aiming for. I've had some success already, I (hopefully) now just need to tweak things to get it right.

First, for reference, here's my current preamble:

Code: Select all

\usepackage{fancybox}
\usepackage{color,calc}
\definecolor{shade}{gray}{0.9}

\usepackage[pdfborder={0 0 0}]{hyperref}
\usepackage{multirow}

\renewcommand \thechapter {\@Roman\c@chapter}
\renewcommand \thesection {\@arabic\c@section}
\renewcommand \qedsymbol {$\blacksquare$}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhead{}
\fancyhead[RO,LE]{\bfseries\thepage}
\fancyhead[RE]{\bfseries{\thechapter\ \leftmark}}
\fancyhead[LO]{\bfseries{\thechapter.\rightmark}}
\fancyfoot{}

\renewcommand\section{\@startsection{section}{1}%
  \z@{.7\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\Large\bfseries}}

\renewcommand\subsection{\@startsection{subsection}{2}%
  \z@{.7\linespacing\@plus\linespacing}{.3\linespacing}%
  {\normalfont\bfseries}}


\newtheoremstyle{thaum}{12pt}{18pt}{}{}{\bfseries}{}{\newline}{\thmname{#1}\thmnumber{ #2:}\thmnote{ \bfseries{#3}}}
\theoremstyle{thaum}
\newtheorem{thaum}{Theorem}[section]
\renewenvironment{thm}[1][]%
        {
        %\setlength{\fboxsep}{-\fboxrule}
        \footnotesize\normalfont\ttfamily\raggedright
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\itemsep}{-12pt}
        \setlength{\parsep}{20pt}
        \begin{lrbox}{\@tempboxa}%
        \begin{minipage}{\linewidth-2\fboxsep}
        \begin{thaum}
        }%
        {
        \end{thaum}
        \end{minipage}%
        \end{lrbox}%
        \fcolorbox{black}{white}{\usebox{\@tempboxa}}\newline\newline
        }%

\newtheorem{lemming}{Lemma}[section]
\renewenvironment{lem}[1][]%
        {
        %\setlength{\fboxsep}{-\fboxrule}
        \footnotesize\normalfont\ttfamily\raggedright
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\itemsep}{-12pt}
        \setlength{\parsep}{20pt}
        \begin{lrbox}{\@tempboxa}%
        \begin{minipage}{\linewidth-2\fboxsep}
        \begin{lemming}
        }%
        {
        \end{lemming}
        \end{minipage}%
        \end{lrbox}%
        \fcolorbox{black}{white}{\usebox{\@tempboxa}}\newline\newline
        }%

\newtheorem*{lemmings}{Lemma}
\renewenvironment{lem*}[1][]%
        {
        %\setlength{\fboxsep}{-\fboxrule}
        \footnotesize\normalfont\ttfamily\raggedright
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\itemsep}{-12pt}
        \setlength{\parsep}{20pt}
        \begin{lrbox}{\@tempboxa}%
        \begin{minipage}{\linewidth-2\fboxsep}
        \begin{lemmings}
        }%
        {
        \end{lemmings}
        \end{minipage}%
        \end{lrbox}%
        \fcolorbox{black}{white}{\usebox{\@tempboxa}}\newline\newline
        }%

\newtheorem{exam}{Example}[section]
\renewenvironment{example}{\begin{exam}}{\end{exam}}

\newtheoremstyle{algae}{12pt}{18pt}{}{}{\bfseries}{}{\newline}{\thmname{#1}\thmnumber{ #2:}\thmnote{ \bfseries{#3}}}
\theoremstyle{algae}
\newtheorem{algae}{Algorithm}[section]
\renewenvironment{algorithm}[1][]%
        {
        %\setlength{\fboxsep}{-\fboxrule}
        \footnotesize\normalfont\ttfamily\raggedright
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\itemsep}{-12pt}
        \setlength{\parsep}{20pt}
        \begin{lrbox}{\@tempboxa}%
        \begin{minipage}{\linewidth-2\fboxsep}
        \begin{algae}
        }%
        {
        \end{algae}
        \end{minipage}%
        \end{lrbox}%
        \fcolorbox{white}{shade}{\usebox{\@tempboxa}}\newline\newline
        }%


\newtheoremstyle{algaes}{12pt}{18pt}{}{}{}{}{0pt}{}
\theoremstyle{algaes}
\newtheorem*{algaes}{ }
\renewenvironment{algorithm*}[1][]%
        {
        %\setlength{\fboxsep}{-\fboxrule}
        \footnotesize\normalfont\ttfamily\raggedright
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\itemsep}{-12pt}
        \setlength{\parsep}{20pt}
        \begin{lrbox}{\@tempboxa}%
        \begin{minipage}{\linewidth-2\fboxsep}
        \begin{algaes}
        }%
        {
        \end{algaes}
        \end{minipage}%
        \end{lrbox}%
        \fcolorbox{white}{shade}{\usebox{\@tempboxa}}\newline\newline
        }%
  • I'm looking to enclose the Theorem and Lemma environments with a black-outlined box, and the Algorithm environments with a grey-shaded box. To this end, I've appropriated some code from http://wiki.lyx.org/FAQ/ShadedBox. However, the current implementation puts this box immediately below the preceding text, with no gap. I'd like to have minimum gap that could be extended by LaTeX (currently some pages are becoming ridiculous; display equations have a quarter-page gap above and below because it's the only place it can find to put a gap). Also, the Algorithm environment will sometimes not take a new line at all, and start at the end of the previous line, spanning across the edge of the page on the right-hand side. Obviously this is unacceptable.
  • To avoid having the chapter number in the section headings (and in the header), I've redefined sectionmark. Unfortunately, this has also fouled up all my cross-references to sections and subsections, so that the chapter number doesn't appear there either (which is obviously misleading). Is there any way I can have my cake and eat it too?
  • I'd like to have my ToC include chapters, sections and subsections, and to have each level indented more than the previous. Currently, sections and subsections are indented equal amounts. How do I go about indenting subsections more than sections?
  • I'm using \nocite{*} and a BibTeX database to create my bibliography; no citations are called in the text, so I don't have any need for numbering there - can I turn it off?
  • I'd like my Example environment, like the Proof environment, to end with a \qed. Currently I've entered these manually, but on the rare occasion when an Example ends with a display equation, the \qedsymbol gets placed a quad after the end of the equation. This clashes with other exampls on the same page, where it is placed at the right margin. I've tried using \qedhere and \qed in various combinations, but the \qedsymbol refuses to match up. Is there any way to force this? If not, is there any way to redefine Example to be in effect a second version of the Proof environment, with numbering and style as I already have in my preamble, so that \qedhere will work?
  • Is it possible to make the table of contents appear as an entry in the table of contents?
  • Is there any way to create a copyright page (rear-of-the-title-page), as I believe KOMA-Script does?
Many thanks in advance for any advice and assistance anyone can provide!

Ed

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Some help tweaking the amsbook class?

Post by Stefan Kottwitz »

Hi Ed,

welcome to the forum!
trogdor wrote:First, for reference, here's my current preamble
It's not a complete preamble. The document class (ok, amsbook) and it's options are missing, you are using the @-Symbol what means there should be \makeatletter somewhere. Or it's not a common tex-document, it may be a .sty file?

If you post a compilable minimal working example demonstrating your questions, it would be easier to provide specific advice. If somebody wants to test a solution before posting a correct answer, he has to complete your code fragment to a compilable document, not everybody will do this work for himself if you don't post compilable code.

Some comments to your questions:
  • trogdor wrote: To avoid having the chapter number in the section headings (and in the header), I've redefined sectionmark.
    Perhaps you mean \thesection?
  • trogdor wrote:I'd like to have my ToC include chapters, sections and subsections, and to have each level indented more than the previous. Currently, sections and subsections are indented equal amounts. How do I go about indenting subsections more than sections?
    You could redefine \l@subsection, for example:

    Code: Select all

    \renewcommand*\l@subsection{\@tocline{2}{0pt}{2.5pc}{5pc}{}}
    Or try the titlesec package.
  • trogdor wrote:I'm using \nocite{*} and a BibTeX database to create my bibliography; no citations are called in the text, so I don't have any need for numbering there - can I turn it off?
    Choose a bibliography style that doesn't use numbering.
  • trogdor wrote:I'd like my Example environment, like the Proof environment, to end with a \qed. Currently I've entered these manually, but on the rare occasion when an Example ends with a display equation, the \qedsymbol gets placed a quad after the end of the equation.
    The ntheorem package improves the placement of endmarks.
  • trogdor wrote:Is it possible to make the table of contents appear as an entry in the table of contents?
    That doesn't make much sense in my opinion. But you can do it by \addcontentsline or \addtocontents.
Stefan
LaTeX.org admin
trogdor
Posts: 6
Joined: Wed Jul 16, 2008 4:28 pm

Some help tweaking the amsbook class?

Post by trogdor »

Stefan_K wrote:welcome to the forum!
Thanks! :)
Stefan_K wrote:It's not a complete preamble. The document class (ok, amsbook) and it's options are missing, you are using the @-Symbol what means there should be \makeatletter somewhere. Or it's not a common tex-document, it may be a .sty file?
Sorry, I should have mentioned, I'm using the LyX editor (hence my post in this subforum); what was posted was the complete preamble as copy-pasted from the Document Settings dialog.
Stefan_K wrote:
trogdor wrote: To avoid having the chapter number in the section headings (and in the header), I've redefined sectionmark.
Perhaps you mean \thesection?
It's been a while since I made the modifications (I put off trying to fix the formatting until I'd finished the content); I've modified both, but can't recall which one changed what.
Stefan_K wrote:You could redefine \l@subsection, for example:

Code: Select all

\renewcommand*\l@subsection{\@tocline{2}{0pt}{2.5pc}{5pc}{}}
Or try the titlesec package.

Choose a bibliography style that doesn't use numbering.
Thanks
Stefan_K wrote:The ntheorem package improves the placement of endmarks.
Is that compatible with the book (AMS) class that I'm using?
Stefan_K wrote:That doesn't make much sense in my opinion. But you can do it by \addcontentsline or \addtocontents.
It's far from the most urgent of my needs :) I think I tried \addcontentsline, but it always gave the wrong page number. I'll look into \addtocontents

Thanks!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Some help tweaking the amsbook class?

Post by Stefan Kottwitz »

trogdor wrote:
Stefan_K wrote:The ntheorem package improves the placement of endmarks.
Is that compatible with the book (AMS) class that I'm using?
ntheorem works with amsmath if you use the amsmath option, for instance:

Code: Select all

\usepackage[amsmath,thmmarks]{ntheorem}
trogdor wrote: I think I tried \addcontentsline, but it always gave the wrong page number. I'll look into \addtocontents
Use \cleardoublepage before:

Code: Select all

\cleardoublepage
\addcontentsline{toc}{chapter}{\contentsname}
\tableofcontents
Stefan
LaTeX.org admin
trogdor
Posts: 6
Joined: Wed Jul 16, 2008 4:28 pm

Some help tweaking the amsbook class?

Post by trogdor »

Stefan_K wrote:
trogdor wrote: Is that compatible with the book (AMS) class that I'm using?
ntheorem works with amsmath if you use the amsmath option, for instance:

Code: Select all

\usepackage[amsmath,thmmarks]{ntheorem}
That didn't work - it seems that LyX's implementation of amsmath automatically includes amsthm, and that this occurs prior to the loading of ntheorem in the preamble. I just tried to construct a test document consisting of the preamble:

Code: Select all

\usepackage[pdfborder={0 0 0}]{hyperref}
\usepackage[amsthm,hyperref,framed,thmmarks]{ntheorem}

\renewtheorem{thm}{Theorem}[section]
And the body:
(Chapter environment)Foo
(Section environment)Bar
(Paragraph environment)Baz
(Theorem (thm) environment)Foobaz

and got four LaTeX errors:

Code: Select all

Package ntheorem error: Theorem style plain already defined.
LaTeX error: Command \openbox already defined
LaTeX error: Command \proofname already defined
LaTeX error: Command \proof already defined
Stefan_K wrote:

Code: Select all

\cleardoublepage
\addcontentsline{toc}{chapter}{\contentsname}
\tableofcontents
That worked, thanks.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Some help tweaking the amsbook class?

Post by Stefan Kottwitz »

trogdor wrote:it seems that LyX's implementation of amsmath automatically includes amsthm, and that this occurs prior to the loading of ntheorem in the preamble.
Perhaps post an example lyx file as attachment.
When I use LyX with amsmath activated, then amsmath and amssymb are loaded but not amsthm. ntheorem will be loaded later with the user specified LaTeX commands.

Stefan
LaTeX.org admin
trogdor
Posts: 6
Joined: Wed Jul 16, 2008 4:28 pm

Some help tweaking the amsbook class?

Post by trogdor »

Stefan_K wrote:Perhaps post an example lyx file as attachment.
When I use LyX with amsmath activated, then amsmath and amssymb are loaded but not amsthm. ntheorem will be loaded later with the user specified LaTeX commands.
Perhaps it's the amsmath.inc bits that are included from amsbook.layout that automatically incorporate amsthm. Sample file is attached.
Attachments
samplefile.zip
(669 Bytes) Downloaded 308 times
trogdor
Posts: 6
Joined: Wed Jul 16, 2008 4:28 pm

Some help tweaking the amsbook class?

Post by trogdor »

I've got some whitespace by using \par\bigskip before \footnotesize in the theorem and lemma environments (in fact, I removed \footnotesize from those, because I didn't want the text that small). I've added \raggedbottom to avoid massive whitespace issues. I've decided to put up with the uneven thmmark positioning.

This leaves the referencing issue. I've managed to sort out the cross-referencing of sections and subsections by adding:

Code: Select all

\renewcommand\p@section{\thechapter.}
\renewcommand\p@subsection{\thechapter.}
The following:

Code: Select all

\renewcommand\p@thm{\thechapter.}
works when I use the built-in theorem style, but when I try it on my boxed theorem style, the cross-referencing reverts back to the without-\thechapter style. I tried:

Code: Select all

\renewcommand\p@thaum{\thechapter.}
and

Code: Select all

\newcommand\p@thaum{\thechapter.}
(thaum is the name of my boxed theorem style), but the first throws an error, and the second has no effect. Where am I going wrong here?

Also, if it's possible I'd like to avoid adding "\thechapter." if the theorem referred to is in the current chapter. I tried using:

Code: Select all

\renewcommand\p@thm{\if \thechapter \c@chapter \else \thechapter.\fi}
in the test document using the built-in theorem style, but that gives unpredictable unwanted results (without even giving the correct ones).

Can anyone offer any more help?

Thanks!
latexforever
Posts: 120
Joined: Fri Nov 14, 2008 9:40 pm

Re: Some help tweaking the amsbook class?

Post by latexforever »

Have you finally found a solution for the automatic qed symbol?
trogdor
Posts: 6
Joined: Wed Jul 16, 2008 4:28 pm

Re: Some help tweaking the amsbook class?

Post by trogdor »

In theory if I'd used a different document class I could have done it easily using one of the fancier theorem packages. Since I didn't want to do that, I used \qedhere where possible and just put up with the misplaced symbol everywhere else. Hacky, irritating, and contrary to the principles of LaTeX and LyX, but what else is a guy to do?
Post Reply