BibTeX에서 문자열을 사용하여 간접적으로 함수 호출

BibTeX에서 문자열을 사용하여 간접적으로 함수 호출

BibTeX 스타일로 간접적인 함수 호출을 수행하는 것이 가능합니까? 즉, .bib? EXECUTE그렇게 할 수 있지만 이 명령문은 함수(?) 내에서 작동하지 않습니다.

현재 해결 방법은 필드 이름을 가져와서 문자열 리터럴과 비교하고 일치하는 경우 해당 함수를 호출하는 것입니다. 이것은 작동하지만 끔찍합니다(아마도 ?이기 때문에 맞을 것입니다 .bst:)
예를 들면 다음과 같습니다.

FUNCTION {format.thesis.type}
{ this.to.prev.status
  this.status.std
  type empty$
    {
      % Leave warnings to callers
      ""
    }
    {
      type "bthesis" =
      {
        bbl.bthesis
      }
      {
        type "mthesis" =
        {
          bbl.mthesis
        }
        {
          type "phdthesis" =
          {
            bbl.phdthesis
          }
          {
            type "Unknown thesis type " swap$ * ", printing it verbatim" * warning$
            type
          }
        if$
        }
      if$
      }
    if$
    }
  if$
  cap.status.std
}

답변1

짐작했듯이 할 수 없습니다.

TeX와 마찬가지로 BibTeX는 해시 테이블에 함수를 저장합니다. TeX는 \csname<control-sequence>\endcsname문자열 literal 에 해당하는 해시 테이블 항목을 가져와야 합니다 <control-sequence>.
BibTeX는 그렇지 않습니다 :-)

이를 위해서는 BibTeX 자체에 해당 기능을 추가해야 합니다(가장 재미있는 작업은 아닐 수 있음).


위로의 선물로 strcase여러분의 작업을 덜 지루하게 만들어 줄 수 있는 기능을 소개합니다.

구문은 다음과 같습니다.

{ Other cases } "{OTHERWISE}"
{ Case n } <string n>
...
{ Case 2 } <string 2>
{ Case 1 } <string 1>
<string> strcase

이 함수는 the를 각각에 대해 strcase비교합니다 (from to : 이것은 역방향 폴란드어 표기이므로 항목을 거꾸로 읽습니다). 일치하는 항목이 발견되면 코드가 실행되고 나머지는 삭제됩니다(여러 문자열이 일치하는 경우에도 마찬가지) ). 일치하는 항목이 없으면 코드가 실행됩니다. 원하는 만큼 많은 쌍을 사용할 수 있지만 마지막 쌍 은 필수이므로 함수가 중지할 위치를 알 수 있습니다.<string><string n>1nCase nOther cases{ Case n } <string n>{ Other cases } "{OTHERWISE}"

귀하의 사례는 다음과 같이 작성될 수 있습니다. (사전 확인 type missing$:

FUNCTION {format.thesis.type}
{ this.to.prev.status
  this.status.std
  type missing$
    {
      % Do something when type is not given
    }
    {
      { "Unknown thesis type "  type ", printing it verbatim" * * warning$ }
                        "{OTHERWISE}"
      { bbl.bthesis }   "bthesis"
      { bbl.mthesis }   "mthesis"
      { bbl.phdthesis } "phdthesis"
      type strcase
    }
  if$
  cap.status.std
}

다음은 코드를 사용하여 컴파일 가능한 예입니다 .bst.

\begin{filecontents*}{test.bst}
ENTRY { type name } { } { }
INTEGERS { strcase.next } % the code requires an integer
STRINGS { s t } % and two strings
FUNCTION { not }
  {   { #0 }
      { #1 }
    if$
  }
FUNCTION { pop.next } { swap$ pop$ }
FUNCTION { strcase.end }
  { #0 'strcase.next :=
    #1
      swap$
      'skip$
    if$
  }
FUNCTION { strcase }
  { #1 'strcase.next :=
      { strcase.next }
      { 's :=
        't :=
        s t =
          {   { swap$ "{OTHERWISE}" = not }
              { pop.next }
            while$
            pop.next
            strcase.end
          }
          { "{OTHERWISE}" t =
              { strcase.end }
              { pop$ s }
            if$
          }
        if$
      }
    while$
  }
FUNCTION { thesis }
  {
    type missing$
      { "Type missing for entry " cite$ * warning$ }
      {
        { "Unknown thesis type "  type ", printing it verbatim" * * warning$ }
          "{OTHERWISE}"
        { "This is a bachelor thesis" warning$ } "bthesis"
        { "This is a master thesis" warning$ }   "mthesis"
        { "This is a doctor thesis" warning$ } "phdthesis"
        type strcase
      }
    if$
  }
READ
ITERATE {call.type$}
\end{filecontents*}
\begin{filecontents*}{test.bib}
@thesis{bach, type = {bthesis}}
@thesis{mast, type = {mthesis}}
@thesis{doct, type = {phdthesis}}
@thesis{unkn, type = {unknown}}
@thesis{void, name = {me}}
\end{filecontents*}
\documentclass{article}
\begin{document}
\nocite*
\bibliography{test}
\bibliographystyle{test}
\end{document}

관련 정보