<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\chapter{å‚è€ƒæ–‡çŒ®}

ç¨å¾®ä¸¥è‚ƒä¸€äº›çš„æ–‡ç«&nbsp;ï¼Œå¾€å¾€ä¼šé™„ä¸Šä¸€äº›ä¸Žæ–‡ç«&nbsp;å†…å®¹å¯†åˆ‡ç›¸å…³çš„å‚è€ƒæ–‡çŒ®ã€‚ç§‘ç&nbsp;”è®ºæ–‡æ›´æ˜¯å¦‚æ­¤ï¼Œç‰›é¡¿éƒ½è¯´è¿‡è‡ªå·±æ˜¯ç«™åœ¨å·¨äººçš„è‚©è†€ä¸Šåšäº‹æƒ…çš„ã€‚å‚è€ƒæ–‡çŒ®ä¾¿æ˜¯å·¨äººã€‚ä»»ä½•ä¸€ä¸ª \TeX\ ç³»ç»Ÿçš†ä¸æ•¢å¯¹æ”¯æŒå‚è€ƒæ–‡çŒ®æŽ’ç‰ˆè¿™ä¸€äº‹å®œæŽ‰ä»¥è½»å¿ƒï¼Œå¦åˆ™ \TeX\ æ—&nbsp;ä»¥ä¸ºç§‘æŠ€æ–‡çŒ®æŽ’ç‰ˆè½¯ä»¶ä¹‹å…ˆé©±å’Œå…¸èŒƒã€‚

\section{\BibTeX}

å¤§å¤šæ•° \TeX\ ç³»ç»Ÿåœ¨æŽ’ç‰ˆå‚è€ƒæ–‡çŒ®æ—¶ï¼Œçš†éœ€ä¾èµ– bibtex ç¨‹åºã€‚ç”± bibtex åŸºäºŽæ–‡çŒ®æ•°æ®æ–‡ä»¶ç”Ÿæˆå‚è€ƒæ–‡çŒ®åˆ—è¡¨ä¿¡æ¯ï¼Œç„¶åŽäº¤ç”± \TeX\ è¿›è¡ŒæŽ’ç‰ˆï¼Œè¿™ä¸€è¿‡ç¨‹é€šå¸¸æ˜¯è‡ªåŠ¨è¿›è¡Œçš„ï¼Œå¹¶ä¸éœ€è¦ç”¨æˆ·äº†è§£å’Œå¹²é¢„ã€‚\ConTeXt\ çŽ°åœ¨ä¸éœ€è¦ä¾èµ– bibtex ç¨‹åºï¼Œå®ƒå·²è‡ªèº«å†…éƒ¨å®žçŽ°äº† bibtex çš„å…¨éƒ¨åŠŸèƒ½ã€‚æœ¬æ–‡æ¡£åœ¨è°ˆåŠ \BibTeX æ—¶ï¼Œä¸»è¦æŒ‡å…¶æ–‡çŒ®æ•°æ®æ&nbsp;¼å¼ã€‚

\BibTeX\ æ–‡çŒ®æ•°æ®æ–‡ä»¶æ˜¯çº¯æ–‡æœ¬æ–‡ä»¶ï¼Œå…¶ä¸­åŒ…å«ç€è®ºæ–‡ã€ä¸“è‘—å’Œæ‰‹å†Œç­‰æ–‡çŒ®æ•°æ®ã€‚ä¾‹å¦‚ï¼Œä¸€ç¯‡æœŸåˆŠè®ºæ–‡ï¼Œå…¶æ•°æ®æ&nbsp;¼å¼ä¸º

\starttyping
@article{knuth-1984-literate,
  title={Literate programming},
  author={Knuth, Donald Ervin},
  journal={The computer journal},
  volume={27},
  number={2},
  pages={97--111},
  year={1984},
  publisher={Oxford University Press}
}
\stoptyping

\noindent å†ä¾‹å¦‚ä¸€æœ¬ä¸“è‘—ï¼Œå…¶æ•°æ®æ&nbsp;¼å¼ä¸º

\starttyping
@book{knuth-1986-texbook,
  title={The texbook},
  author={Knuth, Donald Ervin and Bibby, Duane},
  volume={1993},
  year={1986},
  publisher={Addison-Wesley Reading, MA}
}
\stoptyping

çŽ°åœ¨ï¼Œä¸ºäº†å­¦ä¹&nbsp; \ConTeXt\ çš„å‚è€ƒæ–‡çŒ®æŽ’ç‰ˆåŠŸèƒ½ï¼Œå¯å°†ä¸Šè¿°æ–‡çŒ®æ•°æ®ä¿å­˜ä¸ºä¸€ä»½æ–‡æœ¬æ–‡ä»¶ï¼Œä¾‹å¦‚ foo.bibï¼Œå°†è¯¥æ–‡ä»¶ä½œä¸ºæ–‡çŒ®æ•°æ®æ–‡ä»¶ã€‚

åœ¨ foo.bib ç›¸åŒç›®å½•ä¸‹ï¼Œå»ºç«‹ \ConTeXt\ æºæ–‡ä»¶ï¼Œä¾‹å¦‚ foo.texï¼Œå…¶å†…å®¹ä¸º

\starttyping[option=TEX]
\usebtxdataset[foo.bib] % åŠ&nbsp;è½½ foo.bib
\starttext
Knuth åŸºäºŽæ–‡å­¦ç¼–ç¨‹\cite[knuth-1984-literate]æŠ€æœ¯å¼€å‘äº†
\TeX\ ç³»ç»Ÿ\cite[knuth-1986-texbook]ã€‚
\blank
\placelistofpublications
\stoptext
\stoptyping
\noindent ç¼–è¯‘ foo.texï¼Œå¯å¾—ä»¥ä¸‹ç»“æžœï¼š
\blank[line]
\midaligned{\externalfigure[06/bibtex-example-01.pdf]}
\blank[line]

\section{æ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼}

ä¸Šä¸€èŠ‚ç¤ºä¾‹ä¸­çš„æ–‡çŒ®åˆ—è¡¨æ˜¯ \ConTeXt\ é»˜è®¤æ&nbsp;·å¼ï¼Œé™¤æ­¤ä¹‹å¤–ï¼Œè¿˜æœ‰å…¶ä»–ä¸‰ç§é¢„å®šä¹‰çš„æ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼ï¼šapaï¼Œaps å’Œ chicagoï¼Œå¯åœ¨ \type{\placelistofpublications} ä¹‹å‰ä½¿ç”¨ \type{\usebtxdefinitions} è¿›è¡Œåˆ‡æ¢ã€‚ä¾‹å¦‚ä½¿ç”¨ aps æ&nbsp;·å¼ï¼Œ

\starttyping[option=TEX]
... ... ...
\usebtxdefinitions[aps]
\placelistofpublications
\stoptyping
\blank[line]
\midaligned{\externalfigure[06/bibtex-example-02.pdf]}
\blank[line]

å¯¹äºŽé¢„å®šä¹‰æ&nbsp;·å¼ï¼Œå¯ä»¥è¿›è¡Œè°ƒæ•´ã€‚ä¾‹å¦‚ï¼Œç¼©å°æ–‡çŒ®åºå·åŽçš„ç©ºç™½é—´è·ï¼Œ

\starttyping[option=TEX]
\setupbtxlist[apa][distance=.5em,width=fit]
\stoptyping
\blank[line]
\midaligned{\externalfigure[06/bibtex-example-03.pdf]}

\section{è‡ªå®šä¹‰æ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼}

ä¹Ÿè®¸ \ConTeXt\ æä¾›çš„å‚è€ƒæ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼å¹¶ä¸ç¬¦åˆä½&nbsp;çš„éœ€æ±‚ï¼Œå›&nbsp;æ­¤ä½&nbsp;ä¼šå¿ä¸ä½æƒ³è‡ªå·±å®šä¹‰ä¸€ç§æ&nbsp;·å¼ã€‚å¯¹æ­¤ï¼Œæˆ‘çš„çœ‹æ³•æ˜¯ï¼Œæ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼å½“ç”±æœŸåˆŠç¼–è¾‘éƒ¨æˆ–ä¸“è‘—å‡ºç‰ˆå•†è´Ÿè´£å®šä¹‰ï¼Œä¸ªäººæ—&nbsp;éœ€å¦‚æ­¤åˆ»æ„ã€‚ä¸è¿‡ï¼Œå€˜è‹¥ä½&nbsp;æ­£æ˜¯æ­¤ç±»æœºæž„å·¥ä½œäººå‘˜ï¼Œéœ€è¦ä¸º \ConTeXt\ å®šä¹‰ç¬¦åˆè‡ªå·±å•ä½è¦æ±‚çš„æ–‡çŒ®æ&nbsp;·å¼ï¼Œä¸‹æ–‡ä»…èƒ½ä¸ºä½&nbsp;æä¾›ä¸€ä¸ªç®€å•çš„ç¤ºä¾‹ï¼Œå¸Œæœ›å¯¹ä½&nbsp;æœ‰æ‰€å¸®åŠ©ã€‚

çŽ°åœ¨ï¼Œå‡è®¾æˆ‘ä»¬è¦å®šä¹‰ä¸€ç§åå­—å«ä½œ foo çš„æ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼ã€‚é¦–å…ˆï¼Œéœ€è¦æŒ‰ç…§ \ConTeXt\ çš„æ–‡ä»¶å‘½åçº¦å®šï¼Œå»ºç«‹ä¸¤ä»½æ–‡ä»¶ï¼Œä¸€ä»½æ˜¯ publ-imp-foo.luaï¼Œä¸€ä»½æ˜¯ publ-imp-foo.texã€‚

åœ¨ publ-imp-foo.lua é‡Œå†™å…¥ä»¥ä¸‹å†…å®¹ï¼š

\starttyping[option=LUA]
local specification = {
  name      = "foo",
  categories = {},
}
local categories = specification.categories
categories.book = {
  required = { "title" },
  optional = {"author", "editor",
              "year",
              "edition", "series", "volume", "number",
              "address", "publisher",
  },
}
return specification
\stoptyping

\noindent ä¸Šè¿°ä»£ç&nbsp;æ˜¯ Lua ä»£ç&nbsp;ï¼Œå®šä¹‰äº†ä¸€ä¸ªè¡¨ã€‚\ConTeXt\ å¯é€šè¿‡è¯¥è¡¨æ˜Žç™½ \BibTeX\ æ–‡çŒ®æ•°æ®é‡Œå“ªäº›ä¿¡æ¯æ˜¯å¿…é¡»çš„ï¼Œå“ªäº›ä¿¡æ¯æ˜¯å¯é€‰çš„ã€‚

åœ¨ publ-imp-foo.tex æ–‡ä»¶ä¸­å†™å…¥ä»¥ä¸‹å†…å®¹

\starttyping[option=TEX]
\startbtxrenderingdefinitions[foo]
\definebtx
  [foo]
  [default=default,specification=foo]

\definebtxrendering
  [foo]
  [specification=foo,numbering=yes]
\stopbtxrenderingdefinitions
\stoptyping

\noindent ä¸Šè¿°ä»£ç&nbsp;å®šä¹‰äº† foo çŽ¯å¢ƒåŠå…¶é»˜è®¤æ&nbsp;·å¼ã€‚æ­¤å¤–ï¼Œ\ConTeXt\ å®žé™…ä¸Šæ˜¯é€šè¿‡ä¸Šè¿°ä»£ç&nbsp;èŽ·çŸ¥ä½&nbsp;åœ¨ publ-imp-foo.lua æ–‡ä»¶é‡Œå®šä¹‰çš„æ•°æ®è¡¨ã€‚

ä¸‹é¢åœ¨ publ-imp-foo.tex æ–‡ä»¶ä¸ºæœŸåˆŠè®ºæ–‡å®šä¹‰æ–‡çŒ®åˆ—è¡¨æ&nbsp;·å¼ï¼š

\starttyping[option=TEX]
\startsetups btx:foo:list:article
  \btxdoif {author} {
    \color[blue]{\btxflush{author}}\btxperiod\btxspace
  }
  \btxdoifelse {title} {
     \color[red]{\btxflush{title}}\btxperiod\btxspace
  }{
     No title\btxperiod\btxspace
  }
  \btxdoif {journal} {
    \color[magenta]{\btxflush{journal}}\btxcomma\btxspace
    \btxflush{year}ï¼Œ\nospace
    \btxdoifelse {volume} {
      \btxspace
      \btxflush{volume}
      \btxdoif {number} {
        \ignorespaces
        \btxleftparenthesis
        \btxflush{number}
        \btxrightparenthesis
      }
    }{
      \btxdoif {number} {
        \btxlabeltext{default:number}
        \btxspace
        \btxflush{number}
      }
    }
    \btxdoif {pages} {
     \nospace\btxcolon\btxspace\btxflush{pages}
    }
    \btxperiod
  }
  \removeunwantedspaces
\stopsetups
\stoptyping

è¿™æ˜¯æœ¬æ–‡æ¡£æˆªæ­¢è‡³æ­¤æœ€ä¸ºå¤æ‚çš„ \TeX\ ä»£ç&nbsp;ï¼Œä½†æ˜¯æ‰€è¡¨è¾¾çš„å†…å®¹éžå¸¸ç®€å•ï¼Œä»…ä»…æ˜¯é’ˆå¯¹æœŸåˆŠè®ºæ–‡è®¾å®šæ–‡çŒ®åˆ—è¡¨åº”å½“å‡ºçŽ°ä½œè€…ã€æ–‡ç«&nbsp;åç§°ã€æœŸåˆŠåç§°ã€æ—¶é—´ã€å·å·ã€æœŸå·ä»¥åŠé¡µç&nbsp;ç­‰ä¿¡æ¯ã€‚å…¶ä¸­ï¼Œ\type{\btxflush} å‘½ä»¤å¯å°† \ConTeXt\ ä»Ž \BibTeX\ æ•°æ®æ&nbsp;¼å¼ä¸­è§£æžå‡ºçš„ä¿¡æ¯è¾“å‡ºåˆ°æŽ’ç‰ˆç»“æžœä¸­ï¼›\type{\btxcomma}ï¼Œ\type{\btxperiod} ä¹‹ç±»çš„å‘½ä»¤çš†ä¸ºè¥¿æ–‡é€—å·ï¼Œå¥å·ç­‰æ&nbsp;‡ç‚¹ç¬¦å·ï¼›\type{\btxspace} æ˜¯è¥¿æ–‡ç©ºæ&nbsp;¼ï¼›\type{\btxdoif} ä¹‹ç±»çš„å‘½ä»¤æ˜¯åˆ¤æ–­ \ConTeXt\ å¯¹ \BibTeX\ æ•°æ®æ&nbsp;¼å¼çš„è§£æžç»“æžœä¸­æ˜¯å¦åŒ…å«æŸé¡¹ã€‚

åœ¨ publ-imp-foo.lua å’Œ publ-imp-foo.tex æ–‡ä»¶åŒä¸€ç›®å½•ä¸‹ï¼Œå»ºç«‹æµ‹è¯•æ–‡ä»¶ï¼Œä¾‹å¦‚ foo.texï¼Œå…¶å†…å®¹ä¸º

\starttyping[option=TEX]
\usebtxdataset[foo.bib] % åŠ&nbsp;è½½ foo.bib
\starttext
Knuth å‘æ˜Žäº†æ–‡å­¦ç¼–ç¨‹è¯­è¨€ WEB\cite[knuth-1984-literate]ã€‚
\blank
\usebtxdefinitions[foo]
\placelistofpublications
\stoptext
\stoptyping

ç”¨äºŽéªŒè¯ä¸Šè¿°å®šä¹‰å‚è€ƒæ–‡çŒ®ç±»è¡¨æ&nbsp;·å¼ foo æ˜¯å¦å¯ç”¨ã€‚ç»“æžœä¸º

\blank[line]
\midaligned{\externalfigure[06/bibtex-example-04.pdf]}

\section{å°ç»“}

å‚è€ƒæ–‡çŒ®çš„æ&nbsp;·å¼ï¼Œæˆ‘æ€»è§‰å¾—æ˜¯å­¦æœ¯ç•Œæ‹¿æ¥å”¬äººçš„ä¸œè¥¿ã€‚å†™ä¸€ç¯‡è®ºæ–‡ï¼Œå³ä½¿é™„ä¸Šå‡&nbsp;åç¯‡å‚è€ƒæ–‡çŒ®ï¼Œç”¨ \ConTeXt\ åˆ—è¡¨è¿›è¡ŒæŽ’ç‰ˆï¼Œä¸Žå†™æ–‡ç«&nbsp;å†…å®¹çš„æ‰€è€—è´¹çš„æ—¶é—´ç›¸æ¯”ï¼Œå®Œå…¨å¯ä»¥å¿½ç•¥ä¸è®¡ã€‚ç„¶è€Œåœ¨å­¦æœ¯ç•Œï¼Œå‚è€ƒæ–‡çŒ®å¦‚ä½•æŽ’ç‰ˆï¼Œå´æˆäº†ä¸€é—¨å­¦é—®ã€‚å€˜è‹¥ä½&nbsp;åŠä¸ªå°æ—¶ä¾ç„¶æœªèƒ½å­¦ä¼šå¦‚ä½•ä¸º \ConTeXt\ å®šä¹‰å‚è€ƒæ–‡çŒ®æ&nbsp;·å¼ï¼Œæˆ‘å»ºè®®éšä¾¿é€‰ä¸€ä¸ª \ConTeXt\ é¢„å®šä¹‰çš„æ&nbsp;·å¼ä½¿ç”¨ã€‚å¾…æ–‡ç«&nbsp;æœ€ç»ˆå®šç¨¿åŽï¼Œå†æ‰‹å·¥ç”¨ \ConTeXt\ åˆ—è¡¨å°†å‚è€ƒæ–‡çŒ®åˆ¶ä½œæˆä½&nbsp;éœ€è¦çš„æ&nbsp;·å¼ã€‚</pre></body></html>