Document Classestufte-latex | BibTeX and Citations as Footnotes

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
abclatex
Posts: 17
Joined: Wed Nov 28, 2012 10:09 pm

tufte-latex | BibTeX and Citations as Footnotes

Post by abclatex »

Hi all,

In the tufte-book document, I'm trying to put the footnotes at the bottom of margin and also adopt BibTeX to cite in most footnotes. But the problem is how to mix them together? I tried several times by using \citep, \footfullcite and etc but didn't work it out. Any suggestions and advices will be welcome. Thanks for your replies.

The desired layout would be like this way:
outcome.JPG
outcome.JPG (43.82 KiB) Viewed 5554 times
Put the footnotes at the bottom of margin could be realized in the following codes:

Code: Select all

\documentclass[a4paper,nols,nobib]{tufte-book}
\usepackage[american]{babel}
\usepackage{blindtext}


%% footnote format
\usepackage{forarray,etoolbox,xifthen,,graphicx,picture,calc,atbegshi,lipsum,color}

\newlength{\vincrement}

\newlength{\fmvorigin}
\newlength{\fmhorigin}
\newlength{\fmvoffset}
\newlength{\nextfmvoffset}
\newlength{\fmvskip}

\setlength{\fmvorigin}{-1in-\voffset-\topmargin-\headheight-\headsep-\textheight}
\makeatletter
    \ifthenelse{\isundefined{\Gm@lmargin}}%
    {\setlength{\fmhorigin}{1in+\hoffset+\oddsidemargin+\textwidth+\marginparsep}}%
    {\setlength{\fmhorigin}{\Gm@lmargin+\textwidth+\marginparsep}}
\makeatother
\setlength{\fmvoffset}{0pt}
\setlength{\fmvskip}{3ex}

\newlength{\tmvorigin}
\newlength{\tmhorigin}
\newlength{\tmvoffset}
\newlength{\nexttmvoffset}
\newlength{\tmvskip}
\newlength{\maxtmnheight}

\setlength{\tmvorigin}{-1in-\voffset-\topmargin-\headheight-\headsep-\baselineskip}
\setlength{\tmhorigin}{\fmhorigin}
\setlength{\tmvoffset}{0pt}
\setlength{\tmvskip}{6ex}

\newcounter{fmn}
\newcounter{tmn}

\newboolean{marginisfull}

\newcommand{\fmnbuffer}{}
\newcommand{\currentfmnqueue}{}
\newcommand{\nextfmnqueue}{}

\newcommand{\tmnbuffer}{}
\newcommand{\currenttmnqueue}{}
\newcommand{\nexttmnqueue}{}

\newcommand{\append}[2]{%
    \ifdefempty{#1}{}{\eappto{#1}{,}}%
    \eappto{#1}{#2}%
    }

\newcommand{\prepend}[2]{%
    \ifdefempty{#1}{}{\epreto{#1}{,}}%
    \epreto{#1}{#2}%
    }

\newcommand{\footmarginnote}[1]{%
    \addtocounter{fmn}{1}%
    \expandafter\newsavebox\csname fmnbox\roman{fmn}\endcsname%
    \expandafter\savebox\csname fmnbox\roman{fmn}\endcsname{\parbox[b]{\marginparwidth}{#1}}%
    \append{\currentfmnqueue}{\roman{fmn}}%
    }

\newcommand{\topmarginnote}[1]{%
    \addtocounter{tmn}{1}%
    \expandafter\newsavebox\csname tmnbox\roman{tmn}\endcsname%
    \expandafter\savebox\csname tmnbox\roman{tmn}\endcsname{\parbox[t]{\marginparwidth}{\vskip-0.75\baselineskip#1}}%
    \append{\currenttmnqueue}{\roman{tmn}}%
    }

\newcommand{\printfmn}{%
    \setlength{\fmvoffset}{0pt}%
    \setboolean{marginisfull}{false}%
    \ifdefempty{\currentfmnqueue}{}{%
        \gdef\nextfmnqueue{}%
        \gdef\fmnbuffer{}%
        \ForEachX{,}{%
            \ifthenelse{\boolean{marginisfull}}%
                {\append{\nextfmnqueue}{\thislevelitem}}%
                {%
                \setlength{\vincrement}%
                    {\fmvskip+\expandafter\ht\csname fmnbox\thislevelitem\endcsname+\dp\csname fmnbox\thislevelitem\endcsname}%
                \setlength{\nextfmvoffset}{\fmvoffset+\vincrement}%
                \ifthenelse{\lengthtest{\nextfmvoffset>\textheight}}{%
                    \setboolean{marginisfull}{true}%
                    \append{\nextfmnqueue}{\thislevelitem}%
                    }{%
                    \prepend{\fmnbuffer}{\thislevelitem}%
                    \addtolength{\fmvoffset}{\vincrement}%
                    }%
                }%
            }%
            {\currentfmnqueue}%
        \setlength{\fmvoffset}{0pt}%
        \ForEachX{,}{%
            \put(\fmhorigin,\fmvorigin+\fmvoffset){\expandafter\usebox\csname fmnbox\thislevelitem\endcsname}%
            \setlength{\vincrement}%
                {\fmvskip+\expandafter\ht\csname fmnbox\thislevelitem\endcsname+\dp\csname fmnbox\thislevelitem\endcsname}%
            \addtolength{\fmvoffset}{\vincrement}%
            }%
            {\fmnbuffer}%
        \global\let\currentfmnqueue\nextfmnqueue%
        }%
    }

\newcommand{\printtmn}{%
    \setlength{\maxtmnheight}{\textheight-\fmvoffset}%
    \setlength{\tmvoffset}{0pt}%
    \setboolean{marginisfull}{false}%
    \ifdefempty{\currenttmnqueue}{}{%
        \gdef\nexttmnqueue{}%
        \gdef\tmnbuffer{}%
        \ForEachX{,}{%
            \ifthenelse{\boolean{marginisfull}}%
                {\append{\nexttmnqueue}{\thislevelitem}}%
                {%
                \setlength{\vincrement}%
                    {\tmvskip+\expandafter\ht\csname tmnbox\thislevelitem\endcsname+\dp\csname tmnbox\thislevelitem\endcsname}%
                \setlength{\nexttmvoffset}{\tmvoffset+\vincrement}%
                \ifthenelse{\lengthtest{\nexttmvoffset>\maxtmnheight}}{%
                    \setboolean{marginisfull}{true}%
                    \append{\nexttmnqueue}{\thislevelitem}%
                    }{%
                    \append{\tmnbuffer}{\thislevelitem}%
                    \addtolength{\tmvoffset}{\vincrement}%
                    }%
                }%
            }%
            {\currenttmnqueue}%
        \setlength{\tmvoffset}{0pt}%
        \ifdefempty{\tmnbuffer}{}{%
            \ForEachX{,}{%
                \put(\tmhorigin,\tmvorigin-\tmvoffset){\expandafter\usebox\csname tmnbox\thislevelitem\endcsname}%
                \setlength{\vincrement}%
                    {\tmvskip+\expandafter\ht\csname tmnbox\thislevelitem\endcsname+\dp\csname tmnbox\thislevelitem\endcsname}%
                \addtolength{\tmvoffset}{\vincrement}%
                }%
                {\tmnbuffer}%
            }%
        \global\let\currenttmnqueue\nexttmnqueue%
        }%
    }

\AtBeginShipout{\AtBeginShipoutUpperLeft{\printfmn\printtmn}}

\makeatletter
\renewcommand{\footnote}[1]{\footnotemark\footmarginnote{\textsuperscript{\@thefnmark}\,#1}}
\makeatother

\begin{document}
Text\footnote{This is the first footnote.}
\blindtext
\blindtext

Text\footnote{This is the second and somewhat longer footnote.}
\blindtext
\blindtext

Text\footnote{This is the third footnote.}
\blindtext
\blindtext

Text\footnote{This is the fourth footnote.}
\blindtext
\end{document}
Adopting bibtex in the tufte-book document in the following codes:

Code: Select all

\documentclass[a4paper,nols,nobib]{tufte-book}
\usepackage[american]{babel}
\usepackage{blindtext}


%% bib
\usepackage{hyphenat}
\usepackage[style=verbose,citepages=omit,dashed=false,maxcitenames=3]{biblatex}

\ExecuteBibliographyOptions{citetracker=true}

\renewbibmacro*{cite:short}{% based on cite:short from verbose.cbx
  \printtext[bibhyperlink]{\printnames{labelname}}%
  \iffieldundef{shorttitle}
    {}
    {\setunit*{\nametitledelim}%
     \printfield[citetitle]{labeltitle}}}

\addbibresource{test.bib}

\begin{document}
Text\autocite[11]{abc}
\blindtext
\blindtext

Text\autocite[12-15]{def} 
\blindtext
\blindtext

Text\autocite[05]{ghi} 
\blindtext
\blindtext

Text\autocite[99-100]{jkl} 
\blindtext

\end{document}
bibtex document:
test.bib
(927 Bytes) Downloaded 431 times
Happy new year!
Last edited by cgnieder on Sat Dec 29, 2012 4:23 pm, edited 1 time in total.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

tufte-latex | BibTeX and Citations as Footnotes

Post by cgnieder »

Hmm, it seems the redefinition of footnote is not compatible with biblatex. I haven't figured out, why, yet.

I'd like to mention for other potential helpers that one needs tufte-common.def 3.5.2 from the tufte-latex svn repository to get biblatex to work with the tufte classes.
site moderator & package author
abclatex
Posts: 17
Joined: Wed Nov 28, 2012 10:09 pm

tufte-latex | BibTeX and Citations as Footnotes

Post by abclatex »

Yes, both cannot work together. Now, I'm trying to use the default natbib to see what will happen.


Edit:
The trial of using natbib also failed: only the BibTeX keys display instead of the whole citation.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

tufte-latex | BibTeX and Citations as Footnotes

Post by cgnieder »

The basic problem is that the whole code for placing footnotes at the bottom of the margin is an experimental one. When you asked how to put the footnotes at the bottom of the margin I remember having found a similar question on TeX.sx where we took the code from only that over there the OP didn't need it to work with twoside option or natbib or biblatex which is why the answers there haven't tried to make it work with them.

As you see the code is rather extensive as it is and is probably not easily adapted. When I find the spare time I'll take a look but I won't promise anything.

Regards
site moderator & package author
abclatex
Posts: 17
Joined: Wed Nov 28, 2012 10:09 pm

tufte-latex | BibTeX and Citations as Footnotes

Post by abclatex »

I know it is kind of tough and really costs time. Hope to find some way to make it.

Many thanks for your help and time, cgnieder.
Post Reply