0

I have limited TeX experience, so please forgive the simple question. I've tried to resolve this issue for hours to no avail.

I am trying to use the code for CJK Chicago-style author-date bibliographies provided in this answer.

I want to adapt the code for use in an R Markdown document in the latest version of RStudio.

The code I am trying to adapt (copied from link above):

\documentclass{article}
\usepackage[fallback]{xeCJK}
\usepackage{xunicode-addon}
\setmainfont[Ligatures={Common, TeX}]{Times New Roman}
\setCJKmainfont[Scale=1]{SimSun}

\usepackage{filecontents} \begin{filecontents}{chicago-notes.dbx} \ProvidesFile{chicago-notes.dbx}[2016/07/24 extended name format for biblatex] \DeclareDatamodelConstant[type=list]{nameparts}{prefix,family,suffix,given,cjk} \end{filecontents} \begin{filecontents}{\jobname.bib} @book{zhaos, title={A Nation-State by Construction: Dynamics of Modern Chinese Nationalism}, author={given=Suisheng, family=Zhao, cjk=趙歲升}, isbn={9780804750011}, year={2011}, address = {Stanford}, publisher={Stanford University Press}} @book{jim, title={Lorem}, author={Smith, Junior, Jim}, year={2009}, address = {Stanford}, publisher={Stanford University Press}} \end{filecontents}

\usepackage[notes,strict,annotation,cmsdate=both,isbn=false, backend=biber]{biblatex-chicago} \addbibresource{\jobname.bib}

% Based on definitions from biblatex.def

\newbibmacro*{name:cjk}[3]{% \usebibmacro{name:delim}{#2#3#1}% \usebibmacro{name:hook}{#2#3#1}% \mkbibnamefamily{#1}% \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}% \ifdefvoid{#3}{}{\bibnamedelimd\mkbibnamecjk{#3}}}

\newbibmacro*{name:cjk-nocjk}[3]{% \usebibmacro{name:delim}{#2#3#1}% \usebibmacro{name:hook}{#2#3#1}% \mkbibnamefamily{#1}% \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}}

\DeclareNameFormat{labelname}{% \ifcase\value{uniquename}% \usebibmacro{name:family} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}% \or \ifdefvoid{\namepartcjk} {\ifuseprefix {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffixi}} {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiveni} {\namepartprefixi} {\namepartsuffixi}}} {\usebibmacro{name:cjk-nocjk} {\namepartfamily}{\namepartgiven}{\namepartcjk}}% \or \ifdefvoid{\namepartcjk} {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:name:cjk-nocjk} {\namepartfamily}{\namepartgiven}{\namepartcjk}}% \fi \usebibmacro{name:andothers}}

\DeclareNameFormat{family-given}{% \ifdefvoid{\namepartcjk} {\ifgiveninits {\usebibmacro{name:family-given} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:family-given} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}}} {\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartcjk}}% \usebibmacro{name:andothers}}

\DeclareNameFormat{given-family}{% \ifdefvoid{\namepartcjk} {\ifgiveninits {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}}} {\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartcjk}}% \usebibmacro{name:andothers}}

\DeclareNameFormat{family-given/given-family}{% \ifdefvoid{\namepartcjk} {\ifnumequal{\value{listcount}}{1} {\ifgiveninits {\usebibmacro{name:family-given} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:family-given} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}}% \ifboolexpe{% test {\ifdefvoid\namepartgiven} and test {\ifdefvoid\namepartprefix}} {} {\usebibmacro{name:revsdelim}}} {\ifgiveninits {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}}}} {\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartcjk}}% \usebibmacro{name:andothers}}

\DeclareFieldFormat[book]{title}{% \mkbibemph{#1}% \iffieldundef{titleaddon}{\isdot}{\nopunct}}

\DeclareFieldFormat{booktitle}{% \mkbibemph{#1}% \iffieldundef{booktitleaddon}{}{\nopunct}}

\DeclareFieldFormat{maintitle}{% \mkbibemph{#1}% \iffieldundef{maintitleaddon}{}{\nopunct}}

\DeclareFieldFormat[article]{title}{% \iffieldundef{title}{}{\mkbibquote{#1}}% \iffieldundef{titleaddon}{\isdot}{\nopunct}}

\DeclareFieldFormat{usere}{\mkbibparens{#1}}

\begin{document} \cite{zhaos,jim}

\printbibliography

\end{document}

The YAML of my .Rmd file is

title: "Title"
output:
  html_document:
    number_sections: T
    includes:
      in_header: "preamble.tex"
link-citations: T
mainfont: Latin Modern
nocite: '@*'
citation_package: biblatex

The file "preamble.tex" consists of the CJK code above. When I knit the file, the "preamble.tex" shows up as text, and the bibliography does not reflect the CJK adaption. (I also tried removing the references in the CJK code and placing them in a "refs.bib" file, which I added to the YAML. This did not help.)

Could anyone provide guidance on how to implement this code in my RStudio IDE? Thanks so much in advance!

  • Welcome to tex.sx. – barbara beeton Jul 09 '23 at 20:25
  • You cannot use biblatex nor specific latex code for a html oputput. For other format that PDF (via LaTeX) you must stay with pandoc-citeproc. – Fran Jul 09 '23 at 20:36
  • @Fran I changed to pdf_document and added latex_engine: xelatex. However, the bibliography still lacks the CJK modifications. Any ideas? – myusername Jul 10 '23 at 00:17
  • I cannot not help with CJK fonts issues, but is unclear what are doing really. Do not show what is your inspiration but a minimal working example (MWE) of your best try. I this case it should be a complete rmakdow file (not part of a YAML header) able to type some main text in chinese and english (just a few words to test) and the external files (i.e., show that there is really in preamble.tex, without irrelevant settings for the issue, and the real refs.bib, with only that two references, of course.) – Fran Jul 10 '23 at 07:13

0 Answers0