0

I am using a custom \textcite macro that I found somewhere. It works nicely except that it makes the opening paren of "Author (year)" part of the link (also colouring it blue) which is not desired.

This is likely just a minor change to the definition of the macro, but the solution eludes me (I don't get where the opening paren is added at all).

enter image description here

Opening paranthesis should not be part of link and should not be coloured.

(M)WE:

\documentclass{scrartcl}

\usepackage{csquotes}

\usepackage[backend=biber,
            bibencoding=utf8,
            hyperref=true,
            natbib=true,
            minnames=1,     %% prevent truncation to year-only
            backref=true, %% TODO REMOVE before final
            bibstyle=apa,
            citestyle=authoryear,
            ]{biblatex}
\DeclareLanguageMapping{english}{english-apa}
\addbibresource{bib.bib}

 \DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{textcite}}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}


\usepackage[table,svgnames]{xcolor}

\definecolor{solblue}{HTML}{268BD2}

\usepackage[pdftex]{hyperref}

\hypersetup{
   pdfhighlight = /P,
   colorlinks=true,
   urlcolor=solblue,
   filecolor=solblue,
   linkcolor=solblue,
   citecolor=solblue,
   raiselinks=true,
   breaklinks,
   unicode
}


\begin{document}

foobar \textcite{thesis_pockrandt} foobar

\end{document}

bib.bib:

@phdthesis{thesis_pockrandt,
    author = {Christopher Maximilian Pockrandt},
    title = {{Approximate String Matching: Improving Data Structures and Algorithms}},
    year = {2019}
}
epR8GaYuh
  • 2,432
  • You are using a combination of APA style and standard authoryear:bibstyle=apa, citestyle=authoryear,. That setup neither conforms to APA style (because you use a different citation style) nor is it particularly customisable (biblatex-apaimplements APA style as closely as possible, so it is much more complex than the standard styles). If you need APA style, load onlystyle=apa,. If you want generic author-year citations, it is better to just loadstyle=authoryear,`. – moewe Apr 08 '20 at 15:25
  • Off-topic: The option bibencoding=utf8, is not required with a current TeX distribution, since biblatex tries to guess the encoding of the TeX file and uses that for the .bib file as well. In most current settings both will default to UTF-8. hyperref=true, offers little advantage of the default setting hyperref=auto,. With both settings biblatex will produce links if and only if the hyperref package is loaded. The only difference is that hyperref=true, will issue a warning if you fail to load the hyperref package. – moewe Apr 08 '20 at 15:28
  • Switching to style=authoryear does not solve the problem. – user188968 Apr 08 '20 at 22:08
  • Oh sorry, I didn't want to imply that it solves the issue immediately. I would like to know if a solution has to use the non-standard combination bibstyle=apa, citestyle=authoryear, or if we can use either style=apa, or style=authoryear, (and if so, which?). – moewe Apr 09 '20 at 05:00
  • Hm, something with style=authoryear would probably work. I have no formal requirements, but when I set this up initially apa looked better for the actual references section but shortened citations in the text weirdly. – user188968 Apr 09 '20 at 15:17

1 Answers1

5

After the discussion in the comments I will answer this question for style=authoryear, (or more precisely, citestyle=authoryear,). If you are interested in a solution for APA style (of course again only citestyle=apa, matters), see BibLaTeX Colors And Links Only The Year Not The Rest Of The Citation.

The principle to get fuller linking is the same as in BibLaTeX Colors And Links Only The Year Not The Rest Of The Citation just adjusted to the (simpler) citation style authoryear.

Again, there are many alternatives to get a greater link area (hyperlink name with biblatex authoryear (biblatex 1.4b), hyperlink name with biblatex authoryear, Biblatex, authoryear-comp, and hyperlinks, Inconsistent bracket color with citet and citep), but I feel this one is the safest (if definitely not the shortest)

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\usepackage{xcolor}
\usepackage{hyperref}


\renewbibmacro*{cite}{%
  \printtext[bibhyperref]{%
    \iffieldundef{shorthand}
      {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
         {\usebibmacro{cite:label}%
          \setunit{\printdelim{nonameyeardelim}}}
         {\printnames{labelname}%
          \setunit{\printdelim{nameyeardelim}}}%
       \usebibmacro{cite:labeldate+extradate}}
      {\usebibmacro{cite:shorthand}}}}

\renewbibmacro*{citeyear}{%
  \printtext[bibhyperref]{%
    \iffieldundef{shorthand}
      {\iffieldundef{labelyear}
         {\usebibmacro{cite:label}}
         {\usebibmacro{cite:labeldate+extradate}}}
      {\usebibmacro{cite:shorthand}}}}

\renewbibmacro*{textcite}{%
  \ifnameundef{labelname}
    {\iffieldundef{shorthand}
       {\printtext[bibhyperref]{%
          \usebibmacro{cite:label}}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nonameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \printtext[bibhyperref]{\usebibmacro{cite:labeldate+extradate}}}
       {\printtext[bibhyperref]{\usebibmacro{cite:shorthand}}}}
    {\printtext[bibhyperref]{\printnames{labelname}}%
     \setunit{%
       \global\booltrue{cbx:parens}%
       \printdelim{nameyeardelim}\bibopenparen}%
     \ifnumequal{\value{citecount}}{1}
       {\usebibmacro{prenote}}
       {}%
     \usebibmacro{citeyear}}}

\renewbibmacro*{cite:shorthand}{%
  \printfield{shorthand}}

\renewbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printfield[citetitle]{labeltitle}}
    {\printfield{label}}}

\renewbibmacro*{cite:labeldate+extradate}{%
  \printlabeldateextra}

\definecolor{solblue}{HTML}{268BD2}

\hypersetup{
   pdfhighlight = /P,
   colorlinks=true,
   urlcolor=solblue,
   filecolor=solblue,
   linkcolor=solblue,
   citecolor=solblue,
   raiselinks=true,
   breaklinks,
   unicode,
}


\addbibresource{biblatex-examples.bib}


\begin{document}
lorem \textcite{sigfridsson} ipsum

dolor \autocite{sigfridsson} sit

\printbibliography
\end{document}

Linked citations with unlinked parentheses.

moewe
  • 175,683
  • Hm, this doesn't work for me: Warning: Macro 'cite:labeldate+extradate' undefined. and ! Undefined control sequence. \blx@unitpunct ...ooltrue {cbx:parens}\printdelim {nameyeardelim}\bibopenparen l.85 lorem \textcite{sigfridsson} ipsum Note that I am on texlive 2015 unfortunately. – user188968 Apr 09 '20 at 16:51
  • @h-2 That will give you a seriously outdated version of biblatex. No chance of an update? – moewe Apr 09 '20 at 17:47
  • No, unfortunately my distribution (FreeBSD) doesn't ship anything newer, yet. And I can't risk changing my enter setup at this point :( – user188968 Apr 09 '20 at 17:58
  • 1
    @h-2 https://gist.github.com/moewew/e0e87aab0437a225cc2741c1b1ab8ee7 should work for old biblatex versions (I aimed for a biblatex version released in 2015). – moewe Apr 09 '20 at 18:11
  • That works great! Except that now the regular \cite is changed to author year instead of author, year. The same for \parencite which also now lacks the comma. And my custom \titlecite now includes single-quotes in the title name for some reason. – user188968 Apr 09 '20 at 18:30
  • 1
    @h-2 The comma in "author year" is gone because I dropped the natbib option. You can get it back by adding natbib=true, back in or with \DeclareDelimFormat{nameyeardelim}{\addcomma\space} (actually, in your outdated version that would have to be \renewcommand*{\nameyeardelim}{\addcomma\spac}). You get single quotes because I load babel with the british option (as a global option). If you use american or english instead, you get double quotes (you can also select one of the other languages supported by csquotes to get typographically correct quotation marks for that locale.) – moewe Apr 09 '20 at 18:39
  • Thanks for your efforts moewe! Unfortunately your solution does not work for the style authoryear-comp due to Error: Too deeply nested parentheses or brackets. Unfortunately this solution you've linked for authoryear-comp does not work either for a current release (see my comment there). Is there any chance you could help? Thanks! – Pontis Apr 24 '21 at 12:23