Bibliography as section in LaTeX / BibTeX - latex

I'm writing a short document using sections rather than chapters as the top-level (documentclass report). However,
\bibliographystyle{amsplain}
\bibliography{general}
causes the bibliography to be inserted as a chapter rather than a section. Is there any way to change this?

By default, the report document class uses \chapter as the bibliography heading level. In contrast, the article document class uses \section as the bibliography heading level. If you're not using \chapter anywhere in your document, you might want to use the article class instead.
If you really want to use the report class, you'll need to redefine the thebibliography environment to use \section instead of \chapter. In the preamble of your document (after the \documentclass line but before the \begin{document} line, insert the following:
\makeatletter
\renewenvironment{thebibliography}[1]
{\section*{\bibname}% <-- this line was changed from \chapter* to \section*
\#mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
\list{\#biblabel{\#arabic\c#enumiv}}%
{\settowidth\labelwidth{\#biblabel{#1}}%
\leftmargin\labelwidth
\advance\leftmargin\labelsep
\#openbib#code
\usecounter{enumiv}%
\let\p#enumiv\#empty
\renewcommand\theenumiv{\#arabic\c#enumiv}}%
\sloppy
\clubpenalty4000
\#clubpenalty \clubpenalty
\widowpenalty4000%
\sfcode`\.\#m}
{\def\#noitemerr
{\#latex#warning{Empty `thebibliography' environment}}%
\endlist}
\makeatother
Now your bibliography will have a \section heading instead of a \chapter heading.
Note that if you load any special bibliography packages, you might want to put this code before those packages are loaded (so you don't overwrite their work).

Look at the package tocibind;
\usepackage[numbib,notlof,notlot,nottoc]{tocbibind}
numbib ensures the Bibliography gets numbered, while the not*-options disables showing the List of Figures, Tables and the TOC itself, respectively.

In my case, I also changed #godbyk's solution to include the section number.
#godbyk's line:
{\section*{\bibname}% <-- this line was changed from \chapter* to \section*
My line:
{\section{\bibname}% <-- this line was changed from \chapter* to \section

For having references at the chapter level, one can use: \addcontentsline{toc}{chapter}{References}.
To have them at the section level, one can use:\addcontentsline{toc}{section}{References}

Related

minitoc: updating tocdepth counter

I am writing my thesis using LaTeX and I would like to include at the beginning of each chapter a mini table of contents including only sections. I am using the minitoc package which I declare in my preamble file. In my main file, I found myself obliged to include the following for the the minitoc to update itself:
% *********************** Adding TOC and List of Figures ***********************
\dominitoc
\tableofcontents
\listoffigures \mtcaddchapter
\listoftables \mtcaddchapter
As I am setting the section counter to 2:
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
The mini tables of contents I am getting includes the subsections (which seems the default minitoc section depth). I tried changing the section toc depth by including:
\newcounter{secttocdepth}
\setcounter{secttocdepth}{1}
everywhere with no success. Your help is very welcome!
Have you tried using
\setcounter{minitocdepth}{1}
like described by the minitoc manual

glossaries package and footnote in LaTeX

I am currently stuck, having two separate glossaries: main & acronyms. Acronyms glossary prints footnotes on first use in the text, but main glossary does not. Is there any way to make any other glossary than acronyms to print footnote on first use of the term? I don't get how to do it.
Here is the code example compiled with TeXnic Center and MiKTeX 2.7:
\documentclass{article}
\usepackage{index}
\usepackage[toc,style=long3colheaderborder,footnote,acronym]{glossaries}
\makeindex
\makeglossaries
\newglossaryentry{appdomain}{name={application domain}, description={app Domain Description...}}
\newglossaryentry{sample}{name={[has been inserted aaa]},description={testing testing 123}}
\newacronym{aca}{aca}{a contrived acronym}
\begin{document}
\section{this is a test section}
This is the test line... a \gls{sample} \gls{appdomain}
\index{entry} and \gls{aca}
\thispagestyle{empty}\cleardoublepage
\printglossary[type=main,title={Glossary},toctitle={Glossary}]
\thispagestyle{empty}\cleardoublepage
\printglossary[type=\acronymtype,title={List of Abbreviations},toctitle={List of Abbreviations}]
\printindex
\thispagestyle{empty}\cleardoublepage
\end{document}
I want sample and appdomain either contain a footnote with description or a footnote stating: please refer to Glossary
Many thanks,
Ovanes
In short, with the glossaries package, you can't get footnotes on the first use for non-acronym glossaries.
However, you can redefine some commands in the preamble (after you \usepackage{glossaries}) to get what you want:
\makeatletter
\renewcommand{\gls#main#displayfirst}[4]{
#1#4\protect\footnote{#2}
}
\makeatother
But that will be really fragile.
I think there is an easier way of doing this. Maybe it's new, but
\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
appears to achieve the exact same thing (correct me if I'm wrong). See the glossaries manual, version 2.03, subsection 2.4.1 changing the format of the text.
Unfortunately, it appears commands like \gls or \autoref does not work in those footnotes.
Following is a good technique, to put a footnote stating where the definitions are:
\label{nom} %put this on the page your term appears, so that it can collect page number
\newcommand{\g}{\footnote{For all abbreviations see the glossary on page \pageref{nom}.}}
I've found this from here.

Excluding a chapter from TOC

In my LaTeX document I've got a table of contents that is automatically generated by collecting everything that is of the form \chapter.
However, I've got an acknowledgements chapter before the table of contents and I don't want it to be automatically labelled "Chapter 1" or captured in the table of contents. Should I be avoiding \chapter altogether and use \section instead? I want to keep the font/formatting that other chapters have though.
The usual way to handle that kind of thing is with the \frontmatter command. Put it after the \begin{document}, and then put \mainmatter right before the \chapter you want to correspond to chapter 1. This may only work in the book class. If you're using \chapter in a report, then \chapter* should also create a chapter that has no number and won't show up in the table of contents.
Indeed, as unknown (google) mentioned, using \frontmatter and \mainmatter is the best solution. This will also adjust your page numbering to lowercase roman numerals for the front matter. However, it works only on book and similar document classes.
In case you're using report, try \chapter*. This will create a chapter without a number that does not appear in the table of contents.
For articles \chapter* does not appear to work. Instead use \section*.

How do you extend article document class in LaTeX?

I don't really need a lot of changes to the default article document class. All I want is:
redefine page margins (I want them to be the same on all pages, but different from the default values);
use title page;
add more elements on the title page (title, author and date is not enough for me, I want company and company logo to be on the title page as well);
change styles of the sections, subsections and subsubsections (I don't want the numbers to be shown, otherwise - they're good).
Perhaps, there are some packages that could be helpful in this case?
There are a number of packages that can help you achieve the results you're looking for. The packages I've selected below are the ones I like, but there is more than one way to do it.
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{paulius-article}[2009/02/25 v0.1 Paulius' modified article class]
% Passes and class options to the underlying article class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
% Load LaTeX's article class with the `titlepage' option so that \maketitle creates a title page, not just a title block
\LoadClass[titlepage]{article}
% Redefine the page margins
% TODO: Adjust margins to your liking
\RequirePackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
% Remove the numbers from all the headings (\section, \subsection, etc.)
\setcounter{secnumdepth}{-1}
% To modify the heading styles more thoroughly use the titlesec package
%\RequirePackage{titlesec}
% Adjust the title page design
% NOTE: This is the default LaTeX title page -- free free to make it look like whatever you want.
% TODO: Add company name and logo somewhere in here.
\newcommand{\maketitlepage}{%
\null\vfil
\vskip 60\p#
\begin{center}%
{\LARGE \#title \par}%
\vskip 3em%
{\large
\lineskip .75em%
\begin{tabular}[t]{c}%
\#author
\end{tabular}\par}%
\vskip 1.5em%
{\large \#date \par}% % Set date in \large size.
\end{center}\par
\#thanks
\vfil\null%
\end{titlepage}%
}
% This some before-and-after code that surrounds the title page. It shouldn't need to be modified.
% I've pulled out the part the actually typesets the title page and placed it in the \maketitlepage command above.
\renewcommand\maketitle{\begin{titlepage}%
\let\footnotesize\small%
\let\footnoterule\relax%
\let \footnote \thanks%
\maketitlepage%
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\#thanks\#empty
\global\let\#author\#empty
\global\let\#date\#empty
\global\let\#title\#empty
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
% TODO: If there are any other article modifications required, add them here.
% That's all, folks!
\endinput
You'll want to read the documentation for the geometry package to adjust the margins. The titlesec package can be used if you want to modify the appearance of the headings (aside from just turning off the numbers).
The titlepage is LaTeX's default title page. You'll need to modify it to add your company name and logo. I've separated out the "stuff to be printed" from all the other code associated with the title page. You should only need to change the \maketitlepage command. In your document, use \maketitle to print the title page.
\documentclass{paulius-article}
\title{My New Document Class}
\author{Paulius}
\usepackage{lipsum}% provides some filler text
\begin{document}
\maketitle% Actually makes a title page
\section{Section Heading}
\subsection{Look no numbers!}
\lipsum[1-10]
\end{document}
Let me know if I missed any of your requirements.
You start with
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{classname}[2009/02/24]
\LoadClass{article}
and add any customizations after that.
UPDATE: I recommend you to read LaTeX2e for class and package writers: PDF, HTML. The examples in Section 3 (The structure of a class or package) should be helpful.
A couple of points that might be interesting:
You can redefine the margins in the header (i.e. before \begin{document}} by reseting the controlling lengths like \setlength{\textwidth}{6.80in}, \setlength{\oddsidemargin}{0.0in} and so on.
\section*{...} will give you un-numbered sections already. Likewise for \subsection* and \subsubsection*. If you do use this trick and also want working references, you might have a look at How do I emit the text content of a reference in LaTeX?.
Have you looked at the titlepage environment?
But perhaps most important, the memoir class may give you all the control you need without any class hacking. Check out the documentation.
Or use Can Berk Güder's suggestion.

How do you display straight quotes instead of curly quotes when using LaTeX's 'listings' package?

I'm using LaTeX's "listings" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the right direction, it looks bad. How can I get straight quotes instead?
I'd prefer not to change or filter the source code itself. Filtering the code to properly change " to `` or '' would work, but this is easier done than said with multiple quotes on a line, or quotes spanning multiple lines. Or you could use symbol or a host of other things. But I'd really like to keep the source unchanged.
Example LaTeX:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
Example output (using Miktex on windows):
(Direct link to image of incorrect output)
I see in the documentation (which should have been distributed with the packge, but is available at http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf) for listings that there is a settable property called upquote to take care of this.
From the documentation:
upquote=⟨true|false⟩ false
determines whether the left and right quote are printed ‘’ or `'. This
key requires the textcomp package if true.
Do something like
\lstset{upquote=true}
before begining the list environment, or use
\begin{lstlisting}[upquote=true]
...
\end{lstlisting}
It is also possible that tis property is already set for you in the appropriate language
definition (see the docs again, big list of predefined languages on page 12).
Use:
\lstloadlanguages{<dialects you need>}
in the header. And then set the language using either of the above conventions for choosing options.
Have you considered using a monospaced (typewriter) font for the listing? The following example works:
\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily} % <<< This line added
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
dmckee's answer above probably works. If you drop your last condition, i.e. you permit changes to the code, then there is a more generic solution, which I tend to use whenever (La)TeX renders a character somehow differently than I expect it to do is to use the \symbol command. I list it here because it can be useful in other situations as well:
\newcommand{\qq}{\symbol{34}} % 34 is the decimal ascii code for "
And then your example:
\begin{lstlisting}
...
print{\qq}The temperature is{\qq},Celsius,{\qq}degrees Celsius{\qq}
...
\end{lstlisting}
Note the curly braces which supposedly take listings back to LaTeX mode (see escapechars option of the package.)
Here is a solution
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}
% in the listings package configuration, try:
literate={"}{\textquotedbl}1,
I had the same problem, using fontspec, and the solution was to not set \defaultfontfeatures{Mapping=tex-text}, but instead setting Mapping=tex-text specifically on only the main and sans font, and leaving the tt font to it's own devices. :)
Maybe it's because I installed listings early as a LaTeX user, but I'm surprised to learn that without the listings package the behaviour is any different.
My solution was similar to David Hanak's, but I used the symbols for double-quote as described in the LaTeX Cheat Sheet (http://stdout.org/~winston/latex)
\newcommand{\QQ}[1]{``#1''}

Resources