1

I follow the answer provided on Answer for similar question

However, when I use that in Overleaf, if give out different output: Suppose:

Smith (1992 & 1993)

end up giving:

bibl

\documentclass[12pt,oneside]{book}  % Remove draft option to show figures (for final draft), otherwise keep for faster production


\usepackage{enumitem} % macros to modify appearance of 'itemize' environments
\usepackage{uorthesis}  % Loads the LaTeX style package

\usepackage[
% backend=biber, 
% style=authoryear, 
style=authoryear-comp, 
% citestyle=authoryear, 
dashed=false,
maxcitenames=2,
maxbibnames=99,
giveninits,
uniquename=init]{biblatex}


\DeclareNameAlias{sortname}{family-given} %for second and third author name

\addbibresource{references.bib}
\usepackage{uorbib}

% for combine both year for an author
\renewcommand{\compcitedelim}{\space\&\space}

% for references 's studies (year)
\renewcommand*{\nameyeardelim}{\addcomma\space}
\newcommand{\mycite}[1]{\citeauthor{#1}'s \citeyear{#1}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printtext[bibhyperref]{\printnames{labelname}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear} % <======================================
    {}
    {(\bibhyperref{\printdate})}
    {\multicitedelim}
    {}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}


\makeatletter
\let\abx@macro@textciteOrig\abx@macro@textcite
\renewbibmacro{textcite}{% <============================================
   \bibhyperref{%
   \let\bibhyperref\relax\relax%
   \abx@macro@textciteOrig%
   }%
}%
\makeatother
% for references 's studies (year)



\usepackage{enumitem} %for tab in Latex (macros to modify appearance of 'itemize' environments)
% Put custom packages to be loaded here
% \usepackage{linguex}  % For linguistic examples
% \usepackage{tikz}     % For drawing

%for section paragraph
% https://tex.stackexchange.com/questions/60209/how-to-add-an-extra-level-of-sections-with-headings-below-subsubsection
\makeatletter
%%%%% Change the style of paragraph headings %%%%%
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%  %for section paragraph
            {-2.5ex\@plus -1ex \@minus -.25ex}%   %for section paragraph
            {1.25ex \@plus .25ex}%  %for section paragraph 
            {\normalfont\normalsize\bfseries}}  %for section paragraph
%%%%% Change the style of subparagraph headings %%%%%
\renewcommand\subparagraph{\@startsection{paragraph}{4}{\z@}%  %for section paragraph
            {-2.5ex\@plus -1ex \@minus -.25ex}%   %for section paragraph
            {1.25ex \@plus .25ex}%  %for section paragraph 
            {\normalfont\normalsize\bfseries}}  %for section paragraph
\makeatother
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

%for paragraph spacing
\setlength{\parindent}{4em} %for paragraph spacing
\setlength{\parskip}{1em} %for paragraph spacing
%for paragraph spacing

%for table spacing to second row
\usepackage{tabularx,seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e}       % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{makecell,siunitx} %for table spacing to second row
%for table spacing to second row

\usepackage{threeparttable} %to add footnote below table
\renewcommand{\TPTtagStyle}{\itshape} % optional
\usepackage{lipsum} % for filler text


% for bold in table using \small
\usepackage{makecell} % for bold in table using \small
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\usepackage{tabulary,siunitx} 
% for bold in table using \small 
\renewcommand\theadgape{}



\usepackage{graphicx}

\usepackage{libertine} %added by ryan


%\usepackage{float}
%\restylefloat{table}


%for table multirow
%\usepackage{multirow} %for table multirow
%\usepackage{multicol} %for table multirow
\usepackage{makecell, multirow, tabularx} %for table multirow
%for table multirow


\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc, positioning,matrix,fit,calc, arrows.meta,
                backgrounds,
                chains}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}              % <---

%---------------- show page layout. don't use in a real document!
% \usepackage{showframe}
% \renewcommand\ShowFrameLinethickness{0.15pt}
% \renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

% for making a comma after the volumn
\renewbibmacro*{volume+number+eid}{%
  \setunit{\addcomma\space}%
  \printfield{volume}%
  \setunit*{\adddot}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}


% \usepackage{parskip}  

\usepackage[hypcap=false]{caption}

\begin{document}

% Title page
\include{structure/title}

% All subsequent pages must be numbered, title page is considered page i,
% front matter is numbered in lowercase Roman numerals
\pagestyle{fancy}
\pagenumbering{roman}
\setcounter{page}{2}
\doublespacing

% Dedication (optional)
\include{structure/dedication}

% Acknowledgments
\include{structure/acknowledgements}

% Abstract
\include{structure/abstract}

% Table of Contents, List of Tables, List of Figures
\tableofcontents

%List of Tables & Figures
\include{structure/tablesfigures}


%%%%%%%%%%%%%%%%%%%% DISSERTATION CONTENT %%%%%%%%%%%%%%%%%%%%

% Regular numbering starts now, first page of first chapter is page 1
\clearpage
\setcounter{page}{0}
\pagenumbering{arabic}

% Body


Test writing \textcite{flowers1992ear, flowers1993sound} and \textcite{peres2003sonification} studies. 
\\
Follow-up in \textcite{flowers1993sound}, blablabla


% References
\clearpage
\addcontentsline{toc}{chapter}{Bibliography}
\markboth{\MakeUppercase{Bibliography}}{}
%\singlespacing
\printbibliography
\appendix
\include{chapters/99-appendix}
\end{document}

Added in uorbib.sty file:

% This contains styling elements for bibliography
% stuff: Entire citation is colored instead of just
% year.
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{uorbib}
  [2018/01/18 v0.01 LaTeX package for UOR thesis]

%% Bib stuff
\DeclareFieldFormat{citehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{#1}}

\DeclareFieldFormat{textcitehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{%
    #1%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}}}

\savebibmacro{cite}
\savebibmacro{textcite}

\renewbibmacro*{cite}{%
  \printtext[citehyperref]{%
    \restorebibmacro{cite}%
    \usebibmacro{cite}}}

\renewbibmacro*{textcite}{%
  \ifboolexpr{
    ( not test {\iffieldundef{prenote}} and
      test {\ifnumequal{\value{citecount}}{1}} )
    or
    ( not test {\iffieldundef{postnote}} and
      test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
  }
    {\DeclareFieldAlias{textcitehyperref}{noformat}}
    {}%
  \printtext[textcitehyperref]{%
    \restorebibmacro{textcite}%
    \usebibmacro{textcite}}}

\endinput
%%
%% End of file `uorbib.sty'.

Added in uorthesis.sty file:

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{uorthesis}
  [2018/01/18 v0.01 LaTeX package for UOR thesis]

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{enumitem}
\setlist{nosep} % Removes too much vertical spacing in lists
\usepackage{booktabs}           % makes tables look good
\usepackage{fancyhdr}           % For page number in the upper right (required) and other running headers(optional)
\usepackage{setspace}           % For double-spacing (required)
\usepackage{titlesec}           % For keeping chapter/chapter titles single-spaced
\usepackage{etoolbox}           % For the flag determining if front matter goes into the TOC
\usepackage{float}              % Helps float images to the top
\RequirePackage{xcolor}
% Define custom colors
\definecolor{darkblue}{rgb}{0, 0, 0.5}
\usepackage[colorlinks=true, allcolors=darkblue]{hyperref}           % Adds hyperlinks in the pdf
\usepackage{csquotes}           % Makes quotes look good
\usepackage[font=small,labelfont={bf,sf}, textfont={sf}, justification=centering]{caption}

%% Font setup
\usepackage{mathptmx}
% \usepackage{lmodern}
\usepackage{helvet}

% Header height (to avoid fancyhdr error)
\setlength{\headheight}{13.6pt}

% Header formatting for regular pages
\fancyhf{}
\fancyhead[L]{\it\small\leftmark}
\fancyhead[R]{\small\thepage}

% Header formatting for chapter title pages
\fancypagestyle{plain}{%
  \fancyhf{}
  \fancyhead[R]{\small\thepage}
  \renewcommand{\headrulewidth}{0pt}
}

% Formatting of chapter and chapter titles: keep them single-spaced in the midst of double-spaced text

\usepackage{sectsty}
\titleformat{\chapter}[hang]{\Huge\sffamily\bfseries}{\thechapter{. }}{0pt}{\Huge}
\allsectionsfont{\normalfont\sffamily\bfseries}
\usepackage{subfigure}
\usepackage[subfigure]{tocloft} % subfigure option only if using subfigure package
\renewcommand{\cfttoctitlefont}{\Huge \bfseries \sffamily} % ToC title
\addto\captionsenglish{
\renewcommand{\listfigurename}{\textsf{List of Figures}}
\renewcommand{\listtablename}{\textsf{List of Tables}}
}

% Flag for whether to add front matter to TOC
\newtoggle{fulltoc}
\toggletrue{fulltoc}  % Change to \togglefalse{fulltoc} to remove front matter
\renewcommand{\contentsname}{Table of Contents}

\endinput
%%
%% End of file `uorthesis.sty'.
aan
  • 2,663
  • 2
    You example may not be minimal enough, as most people here don't want to debug your entire thesis. Try and reduce things down to the absolute minimum that demonstrates the problem on Overleaf. – David Purton Sep 13 '19 at 02:58
  • @DavidPurton, thanks. I found my mistake. I need to delete the file uorbib.sty which contain the \renewbibmacro*{textcite}, \DeclareFieldFormat{textcitehyperref}{%. I hope it will not caused a problem in later on. – aan Sep 13 '19 at 03:11
  • 1
    The definition of the textcite macro in authoryear-comp.cbx is different from in authoryear.cbx. If you are changing it, you'll need to account for these differences. – David Purton Sep 13 '19 at 03:34
  • @DavidPurton. Thanks. Is that mean if I use style=authoryear-comp, I do not use authoryear? – aan Sep 13 '19 at 12:12
  • 2
    Well, sort of. The output of both is similar, but authoryear-comp has extra features to compress the year. This makes its citation macros more complex than authoryear. You can compare the files to see the differences. Compare authoryear.cbx with authoryear-comp.cbx to see the differences in code. But you'll notice that authoryear-comp.bbx just inputs authoryear.bbx without changes, so the two styles have exactly the same output in the bibliography. – David Purton Sep 13 '19 at 14:07

1 Answers1

2

The code in your uorbib.sty looks as though it came from Audrey's answer to hyperlink name with biblatex authoryear (biblatex 1.4b). That answer was written with style=authoryear (specifically citestyle=authoryear) in mind. If you want to use style=authoryear-comp, things may not work as expected. Indeed the definition of \textcite is quite a bit more complex in the -comp styles and so it doesn't come as a huge surprise that things break down.

Not only is the code in uorbib.sty written for authoryear, the modifications in your preamble also assume authoryear and will produce sub-par results with authoryear-comp. The code in your preamble also contradicts uorbib.sty in some places.

In the example below I will collect all biblatex-related code in the preamble to make the example self-contained (and to avoid confusing the living daylight out of me while I worked on the answer). This means that in your real document you should only use this code and not load uorbib.sty.

The implementation of textcite is quite complex in authoryear-comp and means that we can't use \printtext[citehyperref] to produce the link. The punctuation tracker will be upset and will discharge and print punctuation marks in the wrong places. Instead we need to resort to the raw macro \bibhyperref, which is usually an extremely bad idea.

There was more code trying to link textcite, so I removed the duplicate effort.

Furthermore, the redefinition of \parencite did not coincide with the normal definition of \parencite for authoryear-comp, but it was close enough to the standard that it can just be removed entirely.

\documentclass{article}

\usepackage[
  backend=biber, 
  style=authoryear-comp, 
  dashed=false,
  maxcitenames=2,
  maxbibnames=99,
  giveninits,
  uniquename=init]{biblatex}
\usepackage[colorlinks]{hyperref}

\DeclareNameAlias{sortname}{family-given}

\DeclareDelimFormat{nameyeardelim}{\addcomma\space}

\DeclareFieldFormat{citehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{#1}}

\savebibmacro{cite}

\renewbibmacro*{cite}{%
  \printtext[citehyperref]{%
    \restorebibmacro{cite}%
    \usebibmacro{cite}}}

\renewcommand{\compcitedelim}{\addspace\&\space}

\savebibmacro{textcite}

\renewbibmacro*{textcite}{%
  \DeclareFieldAlias{bibhyperref}{noformat}%
  \bibhyperref{%
    \restorebibmacro{textcite}%
    \usebibmacro{textcite}}}


\newcommand{\mycite}[1]{\citeauthor{#1}'s \citeyear{#1}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printtext[bibhyperref]{\printnames{labelname}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear}
    {}
    {(\bibhyperref{\printdate})}
    {\multicitedelim}
    {}


\renewbibmacro*{volume+number+eid}{%
  \setunit{\addcomma\space}%
  \printfield{volume}%
  \setunit*{\adddot}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\addbibresource{biblatex-examples.bib}

\begin{document}
Test writing \textcite{knuth:ct:a,knuth:ct:b}, blablabla

Test writing \cite{knuth:ct:a,knuth:ct:b}, blablabla

Test writing \parencite{knuth:ct:a,knuth:ct:b}, blablabla

\printbibliography
\end{document}

Fully linked citation commands.

moewe
  • 175,683