Skip to content

Instantly share code, notes, and snippets.

@bjoseru
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoseru/2474626f727c3c87433b to your computer and use it in GitHub Desktop.
Save bjoseru/2474626f727c3c87433b to your computer and use it in GitHub Desktop.
A minimal working example of an alphabetically sorted bibliography (compatible with bibtex) that stops working once the babel package is included.
\documentclass{scrlttr2}
%% These two lines will break everything:
% \usepackage[english,german]{babel}
% \selectlanguage{english}
%% Some of the following taken from
%% http://tex.stackexchange.com/questions/18033/using-bibtex-with-letter-class
\makeatletter
\newenvironment{thebibliography}[1]
{\list{\@biblabel{\@Alph\c@enumiv}}% LATIN LETTERS AS REFERENCES
{\settowidth\labelwidth{\@biblabel{#1}}%
\leftmargin\labelwidth
\advance\leftmargin\labelsep
\usecounter{enumiv}%
\let\p@enumiv\@empty
\renewcommand\theenumiv{\@Alph\c@enumiv}}% SAME HERE
\sloppy
\clubpenalty4000
\@clubpenalty \clubpenalty
\widowpenalty4000%
\sfcode`\.\@m}
{\def\@noitemerr
{\@latex@warning{Empty `thebibliography' environment}}%
\endlist}
\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}
\let\bibsection\relax
\def\section*#1{\relax}
\def\@citex[#1]#2{\leavevmode
\let \@citea \@empty \@cite {%
\@for \@citeb :=#2\do {%
\@citea \def \@citea {,\penalty \@m \ }%
\edef \@citeb {\expandafter \@firstofone \@citeb \@empty }%
\if@filesw \immediate \write \@auxout {\string \citation {\@citeb }}\fi%
\@ifundefined {b@\@citeb }%
{\hbox {\reset@font \bfseries ?}\G@refundefinedtrue \@latex@warning {Citation `\@citeb ' on page \thepage \space undefined}}%
{\@cite@ofmt {\expandafter\@Alph\csname b@\@citeb \endcsname }}%
}%
}%
{#1}%
}
\makeatother
\bibliographystyle{unsrt}
\begin{document}
\begin{letter}{TeX.SE}
\opening{Hello,}
When writing scientific reports I like to refer to the references in
the main document using the citation style that has been used
there. Sometimes I need to mention additional references, and for
those I like to use capital latin characters to number them. Of
course I rely on Bib\TeX\ when writing reports.
Thus, I like to cite \cite{test1} and \cite{test2} separately, but
also \cite{test1,test2}. This all works just fine, as long as I do
not include the babel package.
How can I make commands defined above more robust?
\vspace{2cm}
\noindent References:
\begin{thebibliography}{A}
\bibitem{test1} First reference.
\bibitem{test2} Second reference.
\end{thebibliography}
\end{letter}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment