LaTeX 내에서 bib 파일 병합

LaTeX 내에서 bib 파일 병합

.bib내 참고문헌에 사용하고 싶은 파일이 두 개 있습니다 . 항목이 중복되지 않습니다. 나는 그것에 관한 꽤 많은 포럼 주제를 찾았지만 그 중 어느 것도 나를 만족시키지 못했습니다. 그래서 내 생각은 두 개를 하나 .bib의 파일 로 병합하여 .tex. 가장 편리하게는 이 작업이 LaTeX 내에서 수행됩니다(그래서 저는 bibtool, 또는 참조 소프트웨어를 사용하지 않습니다). 그래서 두 파일을 병합하는 매크로를 만들었습니다.

\newwrite\bibwrite
\newcommand{\concatbib}[2]{%
  \begingroup
  \IfFileExists{#1}%
    {\CatchFileDef{\bibone}{#1}{}} 
    {\let\bibone\empty}
  \IfFileExists{#2}%
    {\CatchFileDef{\bibtwo}{#2}{}}
    {\let\bibtwo\empty}%
  \immediate\openout\bibwrite=MyBib.bib\relax
  \immediate\write\bibwrite{\bibone \bibtwo}%
  \immediate\closeout\bibwrite
  \endgroup
}

이는 기본적으로 다른 질문에서 가져온 것입니다("추가" 모드에서 파일을 어떻게 열 수 있나요?). 이제 문제는 Latex가 파일 내용을 해석하려고 하는데 와 같은 것이 \noexpand원하는 \detokenize대로 작동하지 않는다는 것입니다. 그래서 나는 그것을 그대로 읽어야 합니다. 여기에서 Martin Scharrer의 답변에 따라 시도했습니다.제어 명령 인수.

\def\alltext{
  \begingroup
  \let\do\@makeother % define \do to change the category code of its argument to 'other'
  \dospecials % makro that is a string of every special character preceeded with \do -> all catcodes are changed
  \all@text
}
\def\all@text#1{
  \endgroup
  #1
}

그리고 나는 이것을 다른 매크로 내에서 사용할 것입니다. 그런데 단독으로 테스트해보니 Use of \alldoes not match its Definition 오류가 발생 \alltext하고 여기서 큰 포인트를 놓치고 있는 것 같습니다.

  • \all@text나는 그룹을 닫을 수 있도록 after 의 정의를 넣었다고 생각합니다 \alltext. 내 이해로는 catcode가 변경되는 지역을 정의해야 합니다. 그러나 왜 \all@text의 정의에서 이미 알려져야 하는지 모르겠습니다 \alltext.
  • 지금까지 나는 \@...명령이 원시적인 명령이라는 것을 알고 있었지만 단지 표기법일 뿐이라고 생각했습니다. 더 많은 내용이 있나요?
  • 해당 코드를 작동시키는 방법이 있나요?

답변1

설정과 관련하여 제가 누락한 부분이 있는지 잘 모르겠지만 두 파일을 결합해야 합니까 .bib? 이름이 biblio1.biband 로 지정되면 biblio2.bibBibTeX와 LaTeX는 다음 명령문을 통해 두 파일에 쉽게 액세스할 수 있습니다.

\bibliography{biblio1,biblio2}

패키지 를 사용하는 경우 biblatex선호하는 스타일은 한 쌍의 별도 문을 사용하는 것임을 이해합니다 \addbibresource(패키지 섹션 3.6.1 참조).수동):

\addbibresource{biblio1.bib}
\addbibresource{biblio2.bib}

.bib명령을 사용할 때는 파일 이름 확장자를 제공해야 \addbibresource하지만 명령을 사용할 때는 이 확장자를 제공해서는 안 됩니다 \bibliography.

답변2

TeX 수준에서 정말로 수행하고 싶다면( .bib원하는 만큼 많은 파일을 입력할 수 있기 때문에 실제로는 필요하지 않음) 여기에 해당 작업을 수행하는 매크로 세트가 있습니다. \concatbib쉼표로 구분하여 원하는 수의 bib 파일 이름(확장자 없음) 에 필수 인수를 제공할 수 있습니다 .

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
% The document level command
\NewDocumentCommand{\concatbib}{ O{output} m }
 {
  \heinrich_concatbib:nn { #1 } { #2 }
 }

% Variables and messages
\ior_new:N \l__heinrich_input_stream
\iow_new:N \l__heinrich_output_stream
\msg_new:nnnn { concatbib } { file-exist }
  { File~`#1'~exists.~Not~overwriting.}
  { The~file~`#1'~already~exists.~I'll~ignore~this~command. }

% Internal functions
% First we check that the named output file doesn't exist 
\cs_new_protected:Npn \heinrich_concatbib:nn #1 #2
 {
  \file_if_exist:nTF { #1.bib }
   {
    \msg_error:nnn { concatbib } { file-exist } { #1.bib }
   }
   {
    \__heinrich_concatbib_aux:nn { #1 } { #2 }
   }
 }
% If we're writing, we open an output stream and cycle
% through the second argument, a comma separated list
% of bib file names
\cs_new_protected:Npn \__heinrich_concatbib_aux:nn #1 #2
 {
  \iow_open:Nn \l__heinrich_output_stream { #1.bib }
  \clist_map_inline:nn { #2 } { \__heinrich_read_write:n { ##1 } }
  \iow_close:N \l__heinrich_output_stream
 }
% At each step we read each line of the current .bib file
% and write it to the output stream
\cs_new_protected:Npn \__heinrich_read_write:n #1
 {
  \ior_open:Nn \l__heinrich_input_stream { #1.bib }
  \ior_str_map_inline:Nn \l__heinrich_input_stream
   { \iow_now:Nn \l__heinrich_output_stream { ##1 } }
  \ior_close:N \l__heinrich_input_stream
 }
\ExplSyntaxOff

% This will concatenate in `output.bib'
\concatbib{foo1,foo2}

% This will concatenate in `foo.bib'
\concatbib[foo]{foo1,foo2}

답변3

흠... 저는 작업에 적합한 도구를 사용하는 큰 친구입니다. 따라서 지적으로 깨달음은 있지만 LaTeX에서 이것을 구현하지 않고 기본 OS 기능만 사용합니다(bibtool이나 기타 멋진 기능은 필요하지 않음).

Linux/UNIX/MacOS의 경우 해당 디렉터리에서 bash(또는 쉘이나 터미널)를 열고 다음을 입력합니다.

cat bibone.bib bibtwo.bib >MyBib.bib

Windows에서는 CMD 프롬프트를 열고 다음을 입력합니다.

type bibone.bib bibtwo.bib >MyBib.bib

두 시스템 모두에서 다음을 수행할 수도 있습니다.추가>>대신에 출력을 리디렉션하여 기존 MyBib.bib로 변경합니다 >.

관련 정보