plk / biblatex-apa

APA style for BibLaTeX
90 stars 48 forks source link

Spurious space after \fullcite #97

Closed moewew closed 4 years ago

moewew commented 4 years ago

biblatex-apa v9.6.

In

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

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

\begin{filecontents}[force]{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  date    = {1980},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\fullcite{appleby}T
\printbibliography
\end{document}

there is a space between the output of the \fullcite and the T.

I think I have tracked down the issue to the uses of \printtext in addinfo1 and addinfo2

https://github.com/plk/biblatex-apa/blob/fca032a3b08a296da068364bd6968ac65147466c/tex/latex/biblatex-apa/bbx/apa.bbx#L703-L733

Since the \printtext is called unconditionally, the punctuation buffer may be used and emptied even when nothing needs to be printed.

Here is an attempt to fix that

\makeatletter
\newrobustcmd*{\apablx@savetoggle}[1]{%
  \csletcs{apablx@savedtoggle@#1}{etb@tgl@#1}}

\newrobustcmd*{\apablx@restoretoggle}[1]{%
  \csletcs{etb@tgl@#1}{apablx@savedtoggle@#1}}

\newrobustcmd*{\apablx@savepunctstate}{%
  \apablx@savetoggle{blx@block}%
  \apablx@savetoggle{blx@unit}%
  \apablx@savetoggle{blx@insert}%
  \apablx@savetoggle{blx@lastins}%
  \apablx@savetoggle{blx@keepunit}%
  \let\apablx@savd@unitpunct\blx@unitpunct
  \let\apablx@savd@puncthook\abx@puncthook}

\newrobustcmd*{\apablx@restorepunctstate}{%
  \global\apablx@restoretoggle{blx@block}%
  \global\apablx@restoretoggle{blx@unit}%
  \global\apablx@restoretoggle{blx@insert}%
  \global\apablx@restoretoggle{blx@lastins}%
  \global\apablx@restoretoggle{blx@keepunit}%
  \global\let\blx@unitpunct\apablx@savd@unitpunct
  \global\let\abx@puncthook\apablx@savd@puncthook}

\newrobustcmd{\printtexte}[2][]{%
  \apablx@savepunctstate
  \setbox0=\hbox{#2\foreverunspace}%
  \apablx@restorepunctstate
  \ifdim\wd0=0pt
  \else
    \ifblank{#1}
      {\printtext{#2}}
      {\printtext[#1]{#2}}
  \fi}
\makeatother

\renewbibmacro*{addinfo1}{%
  \printtexte[parens]{%
    \usebibmacro{editor+trans+narr}%
    \setunit*{\addsemicolon\addspace}%
    \printfield{edition}%
    \setunit*{\addcomma\addspace}%
    \ifthenelse{\ifentrytype{report}\OR%
                \ifentrytype{thesis}\OR%
                \ifentrytype{unpublished}\OR%
                \ifentrytype{dataset}\OR%
                \ifentrytype{software}\OR%
                \ifentrytype{audio}\OR%
                \ifentrytype{patent}\OR%
                \ifentrytype{image}}{\usebibmacro{addinfo3}}{}%
    \setunit*{\addcomma\addspace}%
    \ifentrytype{inbook}{\printfield{pages}}{}%
    \setunit*{\addcomma\addspace}%
    \ifentrytype{book}{\printfield{volumes}}{}%
    \setunit*{\addcomma\addspace}%
    \ifentrytype{book}{\printfield{volume}}{}}}

% Additional post title information in brackets
\renewbibmacro*{addinfo2}{%
  \printtexte[brackets]{%
    \iffieldbibstring{entrysubtype}
      {\bibcplstring{\thefield{entrysubtype}}}
      {\printfield{entrysubtype}}%
    \setunit*{\addsemicolon\addspace}%
    \printfield{note}}}

It would need some testing, though.

If you like I can prepare a pull request.

plk commented 4 years ago

I tried to use \printtext to manage the punct buffer at a higher level than individual macros when certain information only appears together but comes from multiple macros that interface with the punct buffer but this seems really messy so if you have an idea about this, that would be very good.

moewew commented 4 years ago

See https://github.com/plk/biblatex-apa/pull/99. As I said, I haven't tested this very thoroughly, but early tests looked alright. Let me know if that breaks anything

plk commented 4 years ago

Test suite has no issues so I'll release new version shortly.

moewew commented 4 years ago

Great!

Did you have a chance to look at https://github.com/plk/biblatex-apa/issues/95 yet? If APA style doesn't want the location info, maybe biblatex-apa should just ignore it and not rely on users not to supply it.