%% This is part of OpTeX project, see http://petr.olsak.net/optex \_codedecl \MakeReference {Reading bib databases <2020-03-13>} % loaded on demand by \usebib \_doc ----------------------------- Loading the `librarian.tex` macro package. See `texdoc librarian` for more information about it. \_cod ----------------------------- \_def\_tmp{} \_let\_errmessageori=\_errmessage % we needn't \errmessage during \input librarian \_def\_errmessage#1{\_def\_tmp{error}} \_let\_newwriteori=\_newwrite % we need not to create \jobname.lbr: \_def\_newwrite#1{\_csname lb@restoreat\_endcsname \_endinput} \_def\_tmpb{\_catcode`\_=12 \_input librarian \_catcode`\_=11 }\_tmpb \_let\_errmessage=\_errmessageori \_let\_newwrite=\_newwriteori \_ifx\_tmp\_empty\_else \_def\_usebib/#1 (#2) #3 {% \_opwarning{eTeX and (pdfTeX or XeTeX or LuaTeX) not detected}% \_immediate\_write16{\_space\_space But librarian package needs it. \_noexpand\usebib ignored.}% } \_endinput \_fi \_private \BibFile \ReadList \SortList \SortingOrder \NameCount \AbbreviateFirstname \CreateField \RetrieveFieldInFor \RetrieveFieldIn ; \_doc ----------------------------- The `\usebib` command. \_cod ----------------------------- \_def\_usebib/#1 (#2) #3 {% \_ifx\_citelist\_empty \_opwarning{No cited items. \_noexpand\usebib ignored}% \_else \_bgroup \_par \_emergencystretch=.3\_hsize \_ifx\_bibpart\_undefined \_def\_bibpart{none}\_fi \_def\_optexbibstyle{#2}% \_setctable\_optexcatcodes \_input bib-#2.opm \_the \_bibtexhook \_let\_citeI=\_relax \_xdef\_citelist{\_citelist\_citelistB}% \_global\_let\_addcitelist=\_writeXcite \_def\_tmp##1[*]##2\_relax{\_def\_tmp{##2}}\_expandafter\_tmp\_citelist[*]\_relax \_ifx\_tmp\_empty\_else % there was \nocite[*] used. \_setbox0=\_vbox{\_hsize=\_maxdimen \_def\_citelist{}\_adef@{\_readbibentry}% \_input #3.bib \_expandafter}\_expandafter\_def\_expandafter\_citelist\_expandafter{\_citelist}% \_fi \_def\_citeI[##1]{\_csname lb@cite\_endcsname{##1}{\_bibpart}{}{}}\_citelist \_BibFile{#3}% \_if s#1\_SortList{\_bibpart}\_fi \_ReadList{\_bibpart}% \_restorectable \_egroup \_fi } \_def\_readbibentry#1#{\_readbibentryA} \_def\_readbibentryA#1{\_readbibentryB#1,,\_relax!.} \_def\_readbibentryB#1#2,#3\_relax!.{\_addto\_citelist{\_citeI[#1#2]}} \_doc ----------------------------- Corrections in librarian macros. \_cod ----------------------------- \_tmpnum=\_catcode`\@ \_catcode`\@=11 \_def\lb@checkmissingentries#1,{% we needn't \errmessage here, only \opmacwarning \_def\lb@temp{#1}% \_unless\_ifx\lb@temp\lb@eoe \lb@ifcs{#1}{fields}% {}% {\_opwarning{\_string\_usebib: entry [#1] isn't found in .bib file(s)}}% \_ea\lb@checkmissingentries \_fi } \_def\lb@readentry#1#2#3,{% space before key have to be ingnored \_def\lb@temp{#2#3}% we need case sensitive keys \_def\lb@next{\_ea\lb@gotoat\lb@gobbletoeoe}% \lb@ifcs\lb@temp{requested}% {\_let\lb@entrykey\lb@temp \lb@ifcs\lb@entrykey{fields}{}% {\lb@defcs\lb@entrykey{fields}{}% \_lowercase{\lb@addfield{entrytype}{#1}}% \_let\lb@next\lb@analyzeentry}}{}% \lb@next } \_let\lb@compareA=\lb@compare \_let\lb@preparesortA=\lb@preparesort \_def\lb@compare#1\lb@eoe#2\lb@eoe{% SpecialSort: \_ifx\lb@sorttype\lb@namestring \_ifx\_sortfield\_undefined \lb@compareA#1\lb@eoe#2\lb@eoe \_else \_ea\_RetrieveFieldInFor\_ea{\_sortfield}\lb@entrykey\lb@temp \_ifx\lb@temp\_empty \_toks1={#1\lb@eoe}\_else \_toks1=\_ea{\lb@temp\lb@eoe}\_fi \_ea\_RetrieveFieldInFor\_ea{\_sortfield}\lb@currententry\lb@temp \_ifx\lb@temp\_empty \_toks2={#2\lb@eoe}\_else \_toks2=\_ea{\lb@temp\lb@eoe}\_fi \_edef\lb@temp{\_noexpand\lb@compareA\_space\_the\_toks1 \_space\_the\_toks2}\lb@temp \_fi \_else \lb@compareA#1\lb@eoe#2\lb@eoe \_fi } \_def\lb@preparesort#1#2\lb@eoe{% \_if#1-% \_def\lb@sorttype{#2}% \_else \_def\lb@sorttype{#1#2}% \_fi \lb@preparesortA#1#2\lb@eoe } \_def\_SpecialSort#1{\_def\_sortfield{#1}} \_def\WriteImmediateInfo#1{} % the existence of .lbr file bocks new reading of .bib \_catcode`\@=\_tmpnum \_doc ----------------------------- Main action per every entry. \_cod ----------------------------- \_def\MakeReference{\_par \_bibskip \_advance\_bibnum by1 \_isdefined{_bim:\_the\_bibnum}\_iftrue \_edef\_tmpb{\_csname _bim:\_the\_bibnum\_endcsname}% \_bibmark=\_ea{\_tmpb}% \_else \_bibmark={}\_fi \_edef\_tmpb{\EntryKey}% \_noindent \_dest[cite:\_the\_bibnum]\_printlabel\EntryKey \_printbib {% \_RetrieveFieldIn{entrytype}\_entrytype \_csname _print:BEGIN\_endcsname \_isdefined{_print:\_entrytype}\_iftrue \_csname _print:\_entrytype\_endcsname \_else \_ifx\_entrytype\_empty \_else \_opwarning{Entrytype @\_entrytype\_space from [\EntryKey] undefined}% \_csname _print:misc\_endcsname \_fi\_fi \_csname _print:END\_endcsname \_ifx\_wref\_wrefrelax\_else \_immediate\_wref\_Xbib{{\EntryKey}{\_the\_bibnum}{\_the\_bibmark}}\_fi }\_par } \_doc ----------------------------- The \`\_bprinta`, \`\_bprintb`, \`\_bprintc`, \`\_bprintv` commands used in the style files: \_cod ----------------------------- \_def\_bprinta {\_bprintb*} \_def\_bprintb #1[#2#3]{% \_def\_bibfieldname{#2#3}% \_if!#2\_relax \_def\_bibfieldname{#3}% \_RetrieveFieldIn{#3}\_bibfield \_ifx\_bibfield\_empty\_else \_RetrieveFieldIn{#3number}\_namecount \_def\_bibfield{\_csname _Read#3\_ea\_endcsname \_csname _pp:#3\_endcsname}% \_fi \_else \_RetrieveFieldIn{#2#3}\_bibfield \_fi \_if^#1^% \_ifx\_bibfield\_empty \_ea\_ea\_ea \_doemptyfield \_else \_ea\_ea\_ea \_dofullfield \_fi \_else \_ea \_bprintaA \_fi } \_def\_dofullfield#1#2{\_def\_dofield##1{#1}\_ea\_dofield\_ea{\_bibfield}} \_def\_doemptyfield#1#2{\_def\_dofield##1{#2}\_ea\_dofield\_ea{\_bibfield}} \_let\_Readauthor=\ReadAuthor \_let\_Readeditor=\ReadEditor \_def\_bprintaA #1#2{\_ifx\_bibfield\_empty #2\_else\_bprintaB #1**\_eee\_fi} \_def\_bprintaB #1*#2*#3\_eee{\_if^#3^#1\_else\_ea\_bprintaC\_ea{\_bibfield}{#1}{#2}\_fi} \_def\_bprintaC #1#2#3{#2#1#3} \_def\_bprintc#1#2{\_bprintcA#1#2**\_relax} \_def\_bprintcA#1#2*#3*#4\_relax{\_ifx#1\_empty \_else \_if^#4^#2\_else#2#1#3\_fi\_fi} \_def\_bprintv [#1]#2#3{\_def\_tmpa{#2}\_def\_tmpb{#3}\_bprintvA #1,,} \_def\_bprintvA #1,{% \_if^#1^\_tmpb\_else \_RetrieveFieldIn{#1}\_tmp \_ifx \_tmp\_empty \_else \_tmpa \_def\_tmpb{}\_def\_tmpa{}% \_fi \_ea \_bprintvA \_fi } \_sdef{_pp:author}{\_letNames\_authorname} \_sdef{_pp:editor}{\_letNames\_editorname} \_def\_letNames{\_let\_Firstname=\Firstname \_let\_Lastname=\Lastname \_let\_Von=\Von \_let\_Junior=\Junior } \_doc ----------------------------- Various macros + multilinguas. \_cod ----------------------------- \_def\_bibwarning{\_opwarning{Missing field "\_bibfieldname" in [\EntryKey]}} \_def\_mtdef#1#2#3#4{\_sdef{_mt:#1:en}{#2} \_sdef{_mt:#1:cs}{#3} \_if$#4$\_slet{_mt:#1:sk}{_mt:#1:cs} \_else \_sdef{_mt:#1:sk}{#4} \_fi } \_endcode %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The file `usebib.opm` implements the command `\usebib/ (