删除 R papaja 文档中多余的 `\author` 和 `\affiliation` 字段

Deleting redundant `\author` and `\affiliation` fields in R papaja document

我正在使用 'papaja' 包和 'apa7' LaTeX 模板创建 R Markdown 文档。当一起使用时,由于 tex 文件中重复的 \author\affiliation 字段,后一个包和模板目前会产生冲突。早些时候,一个 method was found to resolve this conflict 通过将以下 LaTeX 命令添加到序言(通过 YAML header 中的 header-includes)来工作:

  - \renewcommand\author[1]{}
  - \renewcommand\affiliation[1]{}

但是,此方法目前不起作用(我找不到原因)。我已经尝试对上面的代码进行了多次修改,例如\renewcommand\author{\phantom{}}{},但无济于事。

可以通过以下步骤重现该错误:

  1. 在RStudio中,安装开发版的papaja包:

    # Install devtools package if necessary
    if(!"devtools" %in% rownames(installed.packages())) install.packages("devtools")
    
    # Install the stable development verions from GitHub
    devtools::install_github("crsh/papaja")
    
  2. 点击左上角的+按钮,创建R Markdown文档。

  3. 删除新文件中的所有内容并替换为以下内容:

    ---
    title             : "Long title"
    shorttitle        : "Short title"
    
    documentclass     : apa7
    classoption       : man
    output            : papaja::apa6_pdf
    
    header-includes:
      - \authorsnames[1, 2, 2]{first author, second author, third author}
      - \authorsaffiliations{{first affiliation}, {second affiliation}}
    ---
    
    text text text text text text text text text.
    
  4. 编织文档。

  5. 注意控制台出现以下错误:

    ! LaTeX Error: Command \c@NumberOfAuthors already defined.
                   Or name \end... illegal, see p.192 of the manual.
    
    Error: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.
    Execution halted
    
  6. 打开生成的.tex文件,删除\author{\phantom{0}}\affiliation{\phantom{0}}两行,点击编译PDF 按钮。请注意,文档现在编织好了。

对于单个人,上述使用 tex 文件的解决方法可能不会有太大问题。然而,它证明了其他人手稿的可复制性是有问题的。

如果有人可以根据 header-includes 序言中输入的一些 LaTex 代码提出解决方案,我将不胜感激。

非常感谢!



.tex 文件

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  english,
  man]{apa7}
\title{Long title}
\author{\phantom{0}}
\date{}

\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={Long title},
  pdflang={en-EN},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
% Manuscript styling
\usepackage{upgreek}
\captionsetup{font=singlespacing,justification=justified}

% Table formatting
\usepackage{longtable}
\usepackage{lscape}
% \usepackage[counterclockwise]{rotating}   % Landscape page setup for large tables
\usepackage{multirow}       % Table styling
\usepackage{tabularx}       % Control Column width
\usepackage[flushleft]{threeparttable}  % Allows for three part tables with a specified notes section
\usepackage{threeparttablex}            % Lets threeparttable work with longtable

% Create new environments so endfloat can handle them
% \newenvironment{ltable}
%   {\begin{landscape}\begin{center}\begin{threeparttable}}
%   {\end{threeparttable}\end{center}\end{landscape}}
\newenvironment{lltable}{\begin{landscape}\begin{center}\begin{ThreePartTable}}{\end{ThreePartTable}\end{center}\end{landscape}}

% Enables adjusting longtable caption width to table width
% Solution found at http://golatex.de/longtable-mit-caption-so-breit-wie-die-tabelle-t15767.html
\makeatletter
\newcommand\LastLTentrywidth{1em}
\newlength\longtablewidth
\setlength{\longtablewidth}{1in}
\newcommand{\getlongtablewidth}{\begingroup \ifcsname LT@\roman{LT@tables}\endcsname \global\longtablewidth=0pt \renewcommand{\LT@entry}[2]{\global\advance\longtablewidth by ##2\relax\gdef\LastLTentrywidth{##2}}\@nameuse{LT@\roman{LT@tables}} \fi \endgroup}

% \setlength{\parindent}{0.5in}
% \setlength{\parskip}{0pt plus 0pt minus 0pt}

% Overwrite redefinition of paragraph and subparagraph by the default LaTeX template
% See https://github.com/crsh/papaja/issues/292
\makeatletter
\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\parindent}%
  {0\baselineskip \@plus 0.2ex \@minus 0.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries\itshape\typesectitle}}

\renewcommand{\subparagraph}[1]{\@startsection{subparagraph}{5}{1em}%
  {0\baselineskip \@plus 0.2ex \@minus 0.2ex}%
  {-\z@\relax}%
  {\normalfont\normalsize\itshape\hspace{\parindent}{#1}\textit{\addperi}}{\relax}}
\makeatother

% \usepackage{etoolbox}
\makeatletter
\patchcmd{\HyOrg@maketitle}
  {\section{\normalfont\normalsize\abstractname}}
  {\section*{\normalfont\normalsize\abstractname}}
  {}{\typeout{Failed to patch abstract.}}
\patchcmd{\HyOrg@maketitle}
  {\section{\protect\normalfont{\@title}}}
  {\section*{\protect\normalfont{\@title}}}
  {}{\typeout{Failed to patch title.}}
\makeatother

\usepackage{xpatch}
\makeatletter
\xapptocmd\appendix
  {\xapptocmd\section
    {\addcontentsline{toc}{section}{\appendixname\ifoneappendix\else~\theappendix\fi\: #1}}
    {}{\InnerPatchFailed}%
  }
{}{\PatchFailed}
\usepackage{csquotes}
\authorsnames[1, 2, 2]{first author, second author, third author}
\authorsaffiliations{{first affiliation}, {second affiliation}}
\ifXeTeX
  % Load polyglossia as late as possible: uses bidi with RTL langages (e.g. Hebrew, Arabic)
  \usepackage{polyglossia}
  \setmainlanguage[]{english}
\else
  \usepackage[main=english]{babel}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
\fi
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi


\shorttitle{Short title}

\affiliation{\phantom{0}}

\begin{document}
\maketitle

text text text text text text text text text.


\end{document}

我在 Papaja package 上找到了一本书。 link 会将您带到 YAML 部分。我想这就是您要找的。

首先,似乎没有 APA 7 的关联,除非您拥有 Papaja 的开发版本。话虽这么说,在他们的主要 github.

中有一张票

如果将输出设置为 apa6_docx,则不会出现此“and &”错误。 (即使是,您也可以删除它。)您可以从那里将其另存为 PDF。我不确定这是否适合您,但我想我会提到它。

这是它对后续作者(以及更多)的陈述。

---
title             : "Long title"
shorttitle        : "Short title"

author: 
  - name          : "First Author"
    affiliation   : "1"
  - name          : "Second Author"
    affiliation   : "1"
  - name          : "Third Author"
    affiliation   : "2"
  
affiliation:
  - id            : "1"
    institution   : "The University"
  - id            : "2"
    institution   : "The Other University"
    
documentclass     : apa7
classoption       : man
output            : papaja::apa6_docx
---

text text text text text text text text text.

快速破解:

---
title             : "Long title"
shorttitle        : "Short title"

documentclass     : apa7
classoption       : man
output            : papaja::apa6_pdf

header-includes:
  - \xpatchcmd{\authorsnames}{\newcounter{NumberOfAuthors}}{\setcounter{NumberOfAuthors}{0}}{}{}
  - \xpatchcmd{\authorsnames}{\newcounter{NumberOfSuperscripts}}{\setcounter{NumberOfSuperscripts}{0}}{}{}
  - \authorsnames[1, 2, 2]{first author, second author, third author}
  - \authorsaffiliations{{first affiliation}, {second affiliation}}
  - \renewcommand{\affiliation}[1]{}
---

text text text text text text text text text.