1

I would like to color year and author with biblatex. When using natbib for citing, authors and year were blue, but after changing to biblatex only year is dyed in the desired color. Is there a way to make only Author(s) and year blue when cited in text, while (), page references and cf. remain black? I would like this to appear in the printed version as well. It might be a problem of translation, but I found nothing that has addressed this issue before.

Thank you very much ahead!

\documentclass[%
ngerman,english,%
toc=chapterentrywithdots, % Macht, dass auch bei den Chaptern Punkte im Inhaltsverzeichnis sind
BCOR=6mm,cdgeometry=no,%
DIV=13,cdfont=true,
listof=totoc
]{tudscrreprt}
\usepackage{filecontents}
\begin{filecontents}{shortbib.bib}
    @article{greenwade93,
        author  = "George D. Greenwade",
        title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
        year    = "1993",
        journal = "TUGBoat",
        volume  = "14",
        number  = "3",
        pages   = "342--351"
    }
    @article{petritan2010,
        title = {Influence of different cutting types on growth of planted beech and Douglas fir saplings},
        volume = {81},
        issn = {0300-4112},
        url = {http://doi.org/10.4432/0300-4112-81-40},
        doi = {10.4432/0300-4112-81-40},
        pages = {40--52},
        number = {2},
        journaltitle = {Forstarchiv},
        author = {Petriţan, Ion Catalin and Lüpke, Burghard von and Petriţan, Any Mary},
        date = {2010}
    }
    @article{stancioiu2006,
        title = {Regeneration growth in different light environments of mixed species, multiaged, mountainous forests of Romania},
        volume = {125},
        issn = {1612-4669, 1612-4677},
        url = {http://link.springer.com/10.1007/s10342-005-0069-3},
        doi = {10.1007/s10342-005-0069-3},
        pages = {151--162},
        number = {2},
        journaltitle = {European Journal of Forest Research},
        author = {Stancioiu, Petru Tudor and O'Hara, Kevin L.},
        date = {2006-05},
        langid = {english}
    }
\end{filecontents}

%_______________Zitate__________________________%

\usepackage[ style =authoryear, natbib=true, sorting=nyt, maxcitenames=2, mincitenames=1, maxbibnames=30, minbibnames=30, hyperref=true, dashed=false, abbreviate=false, uniquelist=false, % uniquename=false, backend=biber ]{biblatex} \addbibresource{shortbib.bib} % To make et al italic: \renewbibmacro*{name:andothers}{% Based on name:andothers from biblatex.def \ifboolexpr{ test {\ifnumequal{\value{listcount}}{\value{liststop}}} and test \ifmorenames } {\ifnumgreater{\value{liststop}}{1} {\finalandcomma} {}% \andothersdelim\bibstring[\emph]{andothers}} {}}

\AtEveryBibitem{% \clearfield{note}% Delete all 'note' fields \clearfield{day}% Delete all 'day' fields
\clearfield{month}% Delete all 'month' fields }

\renewcommand*{\nameyeardelim}{\addspace} %To remove comma between author and year

\ExecuteBibliographyOptions{url=false, doi=true} \renewcommand*{\mkbibnamelast}[1]{\textsc{#1}} \renewcommand{\mkbibnamefamily}[1]{\textsc{#1}} \renewcommand{\finalnamedelim}{ & } % ampersand instead and

\usepackage{hyperref} \hypersetup{
colorlinks ,citecolor=blue ,linkcolor=yellow ,urlcolor=red }

\ifpdftex{ \usepackage[T1]{fontenc} \usepackage[ngerman=ngerman-x-latest]{hyphsubst} }{ \usepackage{fontspec} %\setmainfont{Charis SIL} } \usepackage{babel}

\begin{document} As \textcite[p.~1]{greenwade93} already stated \autocite[cf.][p.~2]{stancioiu2006}, this is just an example \parencite{petritan2010}. %_______________Bibliography__________________________%

\renewcommand*{\mkbibnamefamily}[1]{\fontfamily{phv}\selectfont \textsc{\textbf{#1}}} \printbibliography[title={Index of sources}]

%_______________End__________________________%

\end{document}

Qiyuan
  • 31
  • 1
    see e.g. https://tex.stackexchange.com/questions/15951/hyperlink-name-with-biblatex-authoryear-biblatex-1-4b – Ulrike Fischer Jul 01 '20 at 13:08
  • The colouring comes from the links biblatex embeds into the citation, so the most natural way would be to extend the link area. This is what the answer in Ulrike's link shows. Getting this right in general is quite tricky, but for authoryear the code is not too bad. In theory an alternative would be to colour the citations without applying any links, which would also not be too complicated, but adding links feels nicer. – moewe Jul 01 '20 at 16:10
  • Thanks Ulrike and Moewe. I give it a try and let you know if I was succesfull. Danke! – Qiyuan Jul 02 '20 at 07:48
  • Wie angegossen! I copied Ulrikes linked example and it runs! Bonus: Since I used natbib before, I can still use the natbib commands without a problem! Only thing that comes to my attention: \citet{ammer_methoden_2004} produces the desired result, with "Ammer et al. (2004), all in blue. But the next sentence starts wit \citet[p.~8]{ammer_zur_2005} --> Ammer et al. (2005, p. 8). Here, only the year is blue. This is a bit striking, since a few words before all has been blue. Is there any way to have author and year blue, while [pre][post] extensions remain black? – Qiyuan Jul 02 '20 at 09:46
  • The great solution provided by David Carlisle, supposed to be for authoryear-comp, is creating the opposite. \citet{ammer_2005}-> all blue. \citet[p.~1{ammer_2005} -> Author and year blue (Hurra) But: \citep[See][p~3]{ammer_2005} -> Here, regardless of the use of [pre] or [post] alone, together or not at all, only the year is blue. – Qiyuan Jul 02 '20 at 10:08
  • Citation linking is a bit of a nightmare if you want to get everything right. I like the approach shown in https://tex.stackexchange.com/q/537426/35864 (the solution is style dependent, the linked answer is for (cite)style=authoryear, which is used in the question, if you want a solution for authoryear-comp the solution will have to look different, but the same strategy can be applied). – moewe Jul 03 '20 at 07:46
  • Unrelated to your question, but you don't need the p.~ in \textcite[p.~1]{greenwade93}. biblatex can automatically detect page (ranges) and add "p."/"pp." as appropriate, so \textcite[1]{greenwade93} is generally preferable. It is worth keeping in mind that finalnamedelim is now a context-sensitive delimiter that should be redefined with \DeclareDelimFormat. I'd also prefer explicit \addspace/\space calls over simple spaces. So instead of \renewcommand{\finalnamedelim}{ \& } I'd have \DeclareDelimFormat{finalnamedelim}{\addspace\&\space}. – moewe Jul 03 '20 at 07:49
  • ... With style=authoryear, sorting=nyt, is already pre-set, so you don't have to mention it explicitly. The biblatex option hyperref=true, is usually not more useful than the preset hyperref=auto, both produce links if and only if \usepackage{hyperref} is loaded, the only difference is that hyperref=true, emits a warning if biblatex detects that \usepackage{hyperref} wasn't loaded. Generally \usepackage{hyperref} should be loaded last (save for a few exceptions - fontenc, fontspec, babel are not amongst them). – moewe Jul 03 '20 at 07:52
  • @moewe That's the point with latex... help options in latex are hard to understand or even find for me. Rightclick-> Open package documentation has never worked for me in Texstudio. Like, if I want to understand why you suggest \DeclareDelimFormat over \renewcommand, where would you look? In R, I just mark the command, press F1 and open the help menu. In TexStudio, when I hover over the command, sometimes a brief help opens par->15.1 \par. But how can I read the full version? Yes, thanks, I just realized yesterday that I don't need to write p~ :D Is it adding a protected space? – Qiyuan Jul 03 '20 at 10:35
  • I use authoryear, so it's working perfectly! …But 95% of the commands are ‘unknown command’s and have a threatening red background. But, another miracle of TexStudio/Latex, the desired results have been achieved, indicating that it somehow still works. ... I exchanged my version with yours using \DeclareDelimFormat. So far it looks identical. Thank you very much for your help! It is exactly what I wanted! – Qiyuan Jul 03 '20 at 10:35
  • The main source of information here would be the biblatex documentation (http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf). You should be able to get the documentation up on your screen by running texdoc biblatex in the command line (texdoc --view biblatex on MikTeX). Yes, by default the space that biblatex adds between the page prefix and the number is not breakable (look up \ppspace in the documentation to find out more). ... – moewe Jul 03 '20 at 11:40
  • ... If the commands are only marked as "unknown" by your editor, you need not worry too much. You only need to worry if LaTeX throws errors when you run it. (Some editors try to help users by parsing the document themselves to find syntax errors and other issues. Partly that parsing relies on hard-coded lists of commands. I assume that some of the commands used in the linked answer are not on your editor's list.) – moewe Jul 03 '20 at 11:42
  • Can we close this as a duplicate of https://tex.stackexchange.com/q/537426/35864 or is there something else we need to address? – moewe Jul 07 '20 at 16:10

0 Answers0