서브파일 사용 시 참고문헌

서브파일 사용 시 참고문헌

나는 박사 학위를 쓰고 있습니다. Biblatex를 사용하여 XeLaTeX에서 논문을 작성하고, 개별 장을 컴파일해야 할 때도 있고, 전체 문서를 컴파일해야 할 때도 있기 때문에 하위 파일을 사용하는데 훌륭하게 작동합니다. 그러나 각 장에는 최종 문서를 컴파일할 때 해당 명령을 꺼서 메인 파일에서 \printbibliography해당 명령만 실행되도록 하고 싶은 명령이 있습니다.\printbibliography

파일 구조는 다음과 같습니다.

Main.tex:

\usepackage{subfiles, biblatex}
\begin{document}

\subfile{Chapter1.tex}

\printbibliography
\end{document}

Chapter1.tex:

\documentclass[Main.tex]{subfiles}
\begin{document}
\cite{Someguy1981}
\printbibliography
\end{document}

답변1

subfiles.sty명령 에서 \subfile다음과 같이 정의됩니다.

\newcommand\subfile[1]{\begingroup\skip@preamble\input{#1}\endgroup}

따라서 아무 작업도 수행하지 않도록 로컬에서 재정의하기 위해 일부 코드를 연결하는 것은 간단합니다 \printbibliography. 예를 들어 기본 파일의 서문에 다음을 추가합니다.

\makeatletter

\newrobustcmd*{\nobibliography}{%
  \@ifnextchar[%]
    {\blx@nobibliography}
    {\blx@nobibliography[]}}

\def\blx@nobibliography[#1]{}

\appto{\skip@preamble}{\let\printbibliography\nobibliography}

\makeatother

biblatex인용 명령을 통해 참고문헌 데이터를 사용할 수 있게 만듭니다 . 따라서 기본 파일 외부에서 참고문헌 항목을 보려는 경우가 아니면 하위 파일에서 를 호출할 필요가 없습니다 \printbibliography.

답변2

나는 또한 Audrey의 접근 방식을 사용했습니다(https://tex.stackexchange.com/a/107111/85983) 한동안은 그랬지만 \printbibliography각 하위 파일의 끝에 글을 써야 해서 짜증이 났습니다. 이제 메인 파일의 프리앰블에서 다음 Latex Hooks를 사용하고 있습니다.

%%% Default start and end for each subfile
\AtBeginDocument{%
}

\AtEndDocument{%
    \printbibliography
    \listoffigures
    \listoftables
    \newpage
    \printacronyms[include-classes=abbrev,name=Acronyms]
}

답변3

하위 파일 버전 2.0부터 조건 매크로를 사용하여 \ifSubfilesClassLoaded{}{}Audrey의 접근 방식과 유사한 작업을 수행할 수도 있습니다(https://tex.stackexchange.com/a/107111/85983).

내 설정에서 MWE는 다음과 같습니다.

main.tex

\documentclass{book}
\usepackage{biblatex}
\usepackage{subfiles} % must be last usepackage

\providecommand{\topdir}{.}
\addglobalbib{\topdir/references.bib} % topdir is needed here so that
                                      % we can resolve the path in the subfile
                                      % correctly. There we re-define the
                                      % topdir macro to the location of the
                                      % bib file.

\begin{document}
\subfile{dir/sub}
\printbibliography[heading=bibintoc]{}
\end{document}

하위텍스

\providecommand{\topdir}{..} % reset all paths to location of main.tex
\documentclass[../main.tex]{subfiles}

\begin{document}
% some content with citations

\ifSubfilesClassLoaded{%
    \printbibliography{}
}{} % we have no 'else' action
\end{document}

답변4

또 다른 접근 방식은 작업 이름으로 하위 파일과 기본 파일을 구별하는 것입니다. 기본 파일이 호출되고 Thesis.tex작업 이름은 일반적으로 Thesis이며 테스트할 수 있습니다.

\IfEq{\jobname}{\detokenize{Thesis}}{}{%
    \AtEndDocument{%
        \printbibliography%
    }
}

이렇게 하면 하위 파일 끝에 참고문헌이 삽입되고 기본 파일에서는 아무 작업도 수행되지 않습니다.

(가능하다면 이전에 이것을 사용하십시오 \usepackage{biblatex}. 그렇지 않으면 경고가 발생할 수 있습니다.\AtEndDocument{\printbibliography}에 대한 정의되지 않은 참조 경고)

관련 정보