\DeclareCiteCommand를 스타일과 함께 사용하는 방법

\DeclareCiteCommand를 스타일과 함께 사용하는 방법

나는 다음과 비슷한 것을 시도하고 있습니다.여백에 Biblatex 각주 내가 그들의 모범을 훔칠 수 있을 정도로 말이다.

내가 하고 싶은 것은 일반적으로 본문에 텍스트를 인용하고 사이드 바에 저자 이름, 날짜, 작품 이름을 차례로 표시하는 것입니다.

이 MWE의 목적을 위해 저는 기본 라텍스만 사용하고 있습니다 \marginpar. (실제 작업에서는 Koma scrnote-layer 항목을 사용하고 있습니다. 하지만 BibLaTeX를 이해하려고 할 때는 그다지 중요하지 않습니다.)

MWE:

\documentclass{article}
\usepackage{blindtext}


% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = {1986},
    title = {The \TeX book},
  }
  @BOOK{KandR,
    AUTHOR    = {Kernighan, Brian W. and Ritchie, Dennis M.},
    TITLE     = {{The C Programming Language Second Edition}},
    PUBLISHER = {Prentice-Hall, Inc.},
    YEAR      = {1988},
}  
\end{filecontents}

\usepackage[]{biblatex}
\addbibresource{\jobname}


\newcommand{\tcite}[1]{
    \textcite{#1}
    \marginpar{
        \citeauthor{#1}, 
        \citeyear{#1}. 
        \citetitle{#1}  
    }
} 

% doc
\begin{document}
\blindtext
\tcite{Knu86}
\blindtext
\tcite{Knu86,KandR}
\blindtext
\end{document}

MSE 출력

파란색 원으로 표시된 텍스트가 완벽하다는 것을 알 수 있습니다. 그러나 빨간색 원으로 표시된 텍스트는 필드별로 정렬되어 있기 때문에 잘못된 것입니다. 그 이유는 물론 명백하다. 내 명령은 키별로 처리하지 않고 모든 키를 함께 처리합니다.

내 현재 명령은 다음과 같습니다

\newcommand{\tcite}[1]{
    \textcite{#1}
    \marginpar{
        \citeauthor{#1}, 
        \citeyear{#1}. 
        \citetitle{#1}  
    }
} 

BibLaTeX를 사용하여 만든 것으로 교체하고 싶다고 생각합니다.\DeclareCiteCommand

그래서 나는 그것에 대해 스윙을했습니다.

\DeclareCiteCommand{\tcite}
{   % prenote
    \usebibmacro{prenote}%
}
{   %loopcode
    \printnames{author}%
    \marginpar{
        \printnames{author}, 
        \printfield{year}. 
        \printfield{title}  
    }
}
{   %sepcode
    \multicitedelim%
}
{\usebibmacro{postnote}}

더 나은 작업

이렇게 하면 파란색 원과 빨간색 원이 모두 분리되어 있는 것을 볼 수 있습니다. 그러나 저자 이름의 스타일 지정(예: 내 설정에 따라 성만 축약되는 것)은 도움이 되지 않습니다. 그리고 나는 사용하지 않고 \textcite그냥 넣기 때문에 printnames{author}거기에서도 어떤 스타일링으로부터도 이익을 얻지 못합니다.

이것은 (내 생각에는) 제가 낮은 수준의 명령을 사용했기 때문입니다. 스타일/구성을 존중하는 더 높은 수준의 명령을 어떻게 사용할 수 있습니까?

답변1

\citeauthor와 같은 고급 명령을 사용하면 안 됩니다 \DeclareCiteCommand. 으로 그렇게 하는 것이 가능 \citeauthor{\thefield{entrykey}}하지만 좋은 생각은 아닙니다.

대신에 사용되는 bibmacros를 사용하십시오.\citeauthor

\newbibmacro{sidecite}{%
  \printnames{labelname}%
  \setunit{\printdelim{nametitledelim}}%
  \printfield[citetitle]{labeltitle}%
  \setunit{\addperiod\space}%
  \printfield{year}}

\textcite귀하의 예에서는 를 다시 만들고 싶었기 때문에 numeric나는 함께갔습니다.

\documentclass{article}
\usepackage{blindtext}


% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Knu86,
  author = {Knuth, Donald E.},
  year = {1986},
  title = {The \TeX book},
}
@BOOK{KandR,
  AUTHOR    = {Kernighan, Brian W. and Ritchie, Dennis M.},
  TITLE     = {{The C Programming Language Second Edition}},
  PUBLISHER = {Prentice-Hall, Inc.},
      YEAR      = {1988},
}  
\end{filecontents}

\usepackage[]{biblatex}


\newbibmacro{sidecite}{%
  \printnames{labelname}%
  \setunit{\printdelim{nametitledelim}}%
  \printfield[citetitle]{labeltitle}%
  \setunit{\addperiod\space}%
  \printfield{year}}

\makeatletter
\DeclareCiteCommand{\cbx@textcite}
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}%
   \setunit{}%
   \marginpar{\usebibmacro{sidecite}}%
   \setunit{%
     \ifbool{cbx:parens}
       {\bibcloseparen\global\boolfalse{cbx:parens}}
       {}%
     \textcitedelim}}
  {}
  {\usebibmacro{textcite:postnote}}
\makeatother

\addbibresource{\jobname.bib}

% doc
\begin{document}
\blindtext
\textcite{Knu86}
\blindtext
\textcite{Knu86,KandR}
\blindtext
\end{document}

숫자 예제 출력, 잘림


authoryear이 더 쉬워졌습니다

\documentclass{article}
\usepackage{blindtext}


% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Knu86,
  author = {Knuth, Donald E.},
  year = {1986},
  title = {The \TeX book},
}
@BOOK{KandR,
  AUTHOR    = {Kernighan, Brian W. and Ritchie, Dennis M.},
  TITLE     = {{The C Programming Language Second Edition}},
  PUBLISHER = {Prentice-Hall, Inc.},
      YEAR      = {1988},
}  
\end{filecontents}

\usepackage[style=authoryear]{biblatex}


\newbibmacro{sidecite}{%
  \printnames{labelname}%
  \setunit{\printdelim{nametitledelim}}%
  \printfield[citetitle]{labeltitle}%
  \setunit{\addperiod\space}%
  \printfield{year}}

\DeclareCiteCommand{\tcite}
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \marginpar{\usebibmacro{sidecite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{\jobname.bib}

% doc
\begin{document}
\blindtext
\tcite{Knu86}
\blindtext
\tcite{Knu86,KandR}
\blindtext
\end{document}

저자 연도 MWE

답변2

\usebibmacro{<macroname>}에서 bib-macro를 호출할 수 있습니다 DeclareCiteCommand. 그러나 DeclareCiteCommandso no 를 사용하여 자체적으로 정의된 항목을 호출할 수는 없습니다 \usebibmacro{citeauthor}.

따라서 새 코드는 다음과 같습니다.

\DeclareCiteCommand{\tcite}%
{\usebibmacro{prenote}}% prenote
{   %loopcode
    \usebibmacro{cite}%
    \marginpar{\usebibmacro{cite}, \printfield{title} \\
}
}
{\multicitedelim}% sepcode
{\usebibmacro{postnote}}

biblatex에 설정된 보다 흥미로운 인용 스타일을 사용하여 이를 실행하면 \usepackage[citestyle=authoryear]{biblatex} 다음이 제공됩니다.

결정된

관련 정보