PhD thesis of Renata Kopečná Angular analysis of B+->K*+(K+pi0)mu+mu- decay with the LHCb experiment
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1349 lines
60 KiB

  1. %% mciteplus.sty
  2. %% enhanced mcite
  3. %% Version 1.1, 2008/09/30
  4. %%
  5. %% Copyright (c) 2008 Michael Shell
  6. %% Support site:
  7. %% http://www.michaelshell.org/tex/mciteplus/
  8. %%
  9. %%*************************************************************************
  10. %% Legal Notice:
  11. %% This code is offered as-is without any warranty either expressed or
  12. %% implied; without even the implied warranty of MERCHANTABILITY or
  13. %% FITNESS FOR A PARTICULAR PURPOSE!
  14. %% User assumes all risk.
  15. %% In no event shall any contributor to this code be liable for any damages
  16. %% or losses, including, but not limited to, incidental, consequential, or
  17. %% any other damages, resulting from the use or misuse of any information
  18. %% contained here.
  19. %%
  20. %% All comments are the opinions of their respective authors.
  21. %%
  22. %% This work is distributed under the LaTeX Project Public License (LPPL)
  23. %% ( http://www.latex-project.org/ ) version 1.3, and may be freely used,
  24. %% distributed and modified. A copy of the LPPL, version 1.3, is included
  25. %% in the base LaTeX documentation of all distributions of LaTeX released
  26. %% 2003/12/01 or later.
  27. %% Retain all contribution notices and credits.
  28. %% ** Modified files should be clearly indicated as such, including **
  29. %% ** renaming them and changing author support contact information. **
  30. %%**********************************************************************
  31. \NeedsTeXFormat{LaTeX2e}
  32. \ProvidesPackage{mciteplus}[2008/09/30 v1.1 enhanced mcite]
  33. % package option conditionals
  34. \newif\if@OPTIONmcitenohooks\@OPTIONmcitenohooksfalse
  35. \newif\if@OPTIONmcitechapterbibrootbib\@OPTIONmcitechapterbibrootbibfalse
  36. \newif\if@OPTIONmcitedebug\@OPTIONmcitedebugfalse
  37. \DeclareOption{debug}{\global\@OPTIONmcitedebugtrue}
  38. \DeclareOption{nohooks}{\global\@OPTIONmcitenohookstrue}
  39. % use ds@ for chapterbibrootbib to keep option local
  40. \def\ds@chapterbibrootbib{\global\@OPTIONmcitechapterbibrootbibtrue}
  41. \ProcessOptions
  42. % first entry in citation or bibliography flag
  43. \newif\if@mcitefirstentry
  44. % first head entry in citation or bibliography flag
  45. \newif\if@mcitefirstheadentry
  46. % entry using star (is a tail) flag
  47. \newif\if@mcitestarentry
  48. % head declared more than once flag
  49. \newif\if@mciteheadredeclared
  50. % sublist block is open flag
  51. \newif\if@mcitesublistopen
  52. % bst indicates that end punctuation would normally be used
  53. \newif\ifmciteBstWouldAddEndPunct
  54. % flag to indicate that the label widths have changed
  55. % and that LaTeX has to be rerun
  56. \newif\if@mciteLaTeXrerun\@mciteLaTeXrerunfalse
  57. % flag to indicate the use of the first optional argument of a macro
  58. \newif\ifmciteMacroOptArgI\mciteMacroOptArgIfalse
  59. % flag to indicate the use of the first optional argument of a macro (local, non user, use)
  60. \newif\if@mciteLocalMacroOptArgI\@mciteLocalMacroOptArgIfalse
  61. % flag to indicate the use of the second optional argument of a macro
  62. \newif\ifmciteMacroOptArgII\mciteMacroOptArgIIfalse
  63. % flag to indicate the use of the star form of a macro
  64. \newif\ifmciteMacroStarForm\mciteMacroStarFormfalse
  65. % flag to indicate the use of the star form of the \cite forwarding macro
  66. \newif\ifmciteCiteStarFwdArg\mciteCiteStarFwdArgfalse
  67. % flag to indicate the use of the sec ID argument for the \cite forwarding macro
  68. \newif\if@mciteCiteSecIDArg\@mciteCiteSecIDArgfalse
  69. % flag to indicate the use of the first optional argument of a bibitem
  70. \newif\ifmciteBibitemOptArgI\mciteBibitemOptArgIfalse
  71. % flag to indicate the use of the first optional argument of the current head bibitem
  72. \newif\ifmciteCurheadBibitemOptArgI\mciteCurheadBibitemOptArgIfalse
  73. % temporary token list
  74. \newtoks\@mcitetmptoksA
  75. % macro to add (unexpanded) to token list
  76. \def\@mciteAppendToTmpToksA#1{\@mcitetmptoksA=\expandafter{\the\@mcitetmptoksA#1}}
  77. % temporary dimen registers
  78. \newdimen\@mcitetmpdima
  79. \newdimen\@mcitetmpdimb
  80. % temporary count registers
  81. \newcount\@mcitetmpcnta
  82. \newcount\@mcitetmpcntb
  83. % count of entries
  84. \newcounter{mcitebibitemcount}
  85. \setcounter{mcitebibitemcount}{0}
  86. % count of sub items
  87. \newcounter{mcitesubitemcount}
  88. % the default entry punctuation and separator
  89. \providecommand{\mcitedefaultmidpunct}{;\space}
  90. \providecommand{\mcitedefaultendpunct}{.}
  91. \providecommand{\mcitedefaultseppunct}{\relax}
  92. % the default sublist label, begin and end macros
  93. \providecommand{\mcitedefaultsublistlabel}{\alph{mcitesubitemcount})\space}
  94. \providecommand{\mcitedefaultsublistbegin}{\relax}
  95. \providecommand{\mcitedefaultsublistend}{\relax}
  96. % the default max width forms
  97. \providecommand{\mcitedefaultmaxwidthbibitemform}{\arabic{mcitebibitemcount}}
  98. \providecommand{\mcitedefaultmaxwidthbibitemforminit}{\mciteorgbibsamplelabel}
  99. \providecommand{\mcitedefaultmaxwidthsubitemform}{\alph{mcitesubitemcount})}
  100. \providecommand{\mcitedefaultmaxwidthsubitemforminit}{a)}
  101. % sample label which is forwarded to \thebibliography
  102. \def\mcitebibsamplelabel{\rule{\mcitemaxwidthbibitem sp}{0.2pt}}
  103. % Aux and track handles
  104. %
  105. % aux used by \mcite
  106. \def\mciteauxout{\@auxout}
  107. % aux used within \mcitethebibliography
  108. \def\mcitebibauxout{\@mainaux}
  109. % current auxout in use
  110. \def\@mcitecurauxout{\mciteauxout}
  111. % This is the unique ID string used to track multiple bibliographies.
  112. \def\mcitetrackID{main}
  113. % for \mcitethebibliography
  114. \def\mcitebibtrackID{main}
  115. % current Track ID in use
  116. \def\@mcitecurtrackID{\mcitetrackID}
  117. % macros for letter code and string tests
  118. \def\@mciteMacrod{d}
  119. \def\@mciteMacron{n}
  120. \def\@mciteMacros{s}
  121. \def\@mciteMacrob{b}
  122. \def\@mciteMacrof{f}
  123. \def\@mciteMacroh{h}
  124. \def\@mciteMacrobibitem{bibitem}
  125. \def\@mciteMacrosubitem{subitem}
  126. % sets the punctuation bst hooks
  127. \long\def\mciteSetBstMidEndSepPunct#1#2#3{\long\def\mcitebstmidpunct{#1}\relax
  128. \long\def\mcitebstendpunct{#2}\long\def\mcitebstseppunct{#3}}
  129. % sets the actual punctuation used
  130. \long\def\mciteSetMidEndSepPunct#1#2#3{\long\def\mcitemidpunct{#1}\relax
  131. \long\def\mciteendpunct{#2}\long\def\mciteseppunct{#3}}
  132. % sets the sublabel bst hooks
  133. \long\def\mciteSetBstSublistLabelBeginEnd#1#2#3{\long\def\mcitebstsublistlabel{#1}\relax
  134. \long\def\mcitebstsublistbegin{#2}\long\def\mcitebstsublistend{#3}}
  135. % sets the actual sublabel used
  136. \long\def\mciteSetSublistLabelBeginEnd#1#2#3{\long\def\mcitesublistlabel{#1}\relax
  137. \long\def\mcitesublistbegin{#2}\long\def\mcitesublistend{#3}}
  138. % sublist mode flags, b and first forms should be set to false unless \@mcitesublistmode is also true
  139. \newif\if@mcitesublistmode\@mcitesublistmodefalse
  140. \newif\if@mcitesublistmodeb\@mcitesublistmodebfalse
  141. \newif\if@mcitesublistmodef\@mcitesublistmodeffalse
  142. \newif\if@mcitesublistmodeh\@mcitesublistmodehfalse
  143. % reset entry counter flag
  144. \newif\ifmciteResetBibitemCount\mciteResetBibitemCounttrue
  145. % error on unknown entries
  146. \newif\ifmciteErrorOnUnknown\mciteErrorOnUnknowntrue
  147. % BST can request a sublist mode using \mciteSetBstSublistMode, but user requests can override it:
  148. % d = default, use current settings
  149. % n = no sublist
  150. % s = sublist
  151. % b = sublistb
  152. % f = sublistfirst
  153. % h = sublistfirst, including single heads
  154. % note that the changes here are local and will not be remembered outside of the \mcitethebibliography environment
  155. \def\mciteSetBstSublistMode#1{\edef\@mcitetemp{#1}\relax
  156. % only make changes if the user mode allows
  157. \ifx\@mcitesublistmode\@mciteMacrod\relax
  158. \ifx\@mcitetemp\@mciteMacrod
  159. \def\@mcitebstsublistmode{d}\else
  160. \ifx\@mcitetemp\@mciteMacron
  161. \def\@mcitebstsublistmode{n}\@mcitesublistmodefalse\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
  162. \ifx\@mcitetemp\@mciteMacros
  163. \def\@mcitebstsublistmode{s}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
  164. \ifx\@mcitetemp\@mciteMacrob
  165. \def\@mcitebstsublistmode{b}\@mcitesublistmodetrue\@mcitesublistmodebtrue\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
  166. \ifx\@mcitetemp\@mciteMacrof
  167. \def\@mcitebstsublistmode{f}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehfalse\else
  168. \ifx\@mcitetemp\@mciteMacroh
  169. \def\@mcitebstsublistmode{h}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehtrue\else
  170. \PackageError{mciteplus}{Unknown mode `#1' in argument to \protect\mciteSetBstSublistMode}%
  171. {Only `d', `n', `s', `b', `f' and `h' are valid.}\relax
  172. \fi
  173. \fi
  174. \fi
  175. \fi
  176. \fi
  177. \fi
  178. \fi}
  179. % User can specify a sublist mode:
  180. % d = default, use current settings, allow BST to choose
  181. % n = no sublist
  182. % s = sublist
  183. % b = sublistb
  184. % f = sublistfirst
  185. % h = sublistfirst, including single heads
  186. \def\mciteSetSublistMode#1{\edef\@mcitetemp{#1}\relax
  187. \ifx\@mcitetemp\@mciteMacrod
  188. \def\@mcitesublistmode{d}\else
  189. \ifx\@mcitetemp\@mciteMacron
  190. \def\@mcitesublistmode{n}\@mcitesublistmodefalse\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
  191. \ifx\@mcitetemp\@mciteMacros
  192. \def\@mcitesublistmode{s}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
  193. \ifx\@mcitetemp\@mciteMacrob
  194. \def\@mcitesublistmode{b}\@mcitesublistmodetrue\@mcitesublistmodebtrue\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
  195. \ifx\@mcitetemp\@mciteMacrof
  196. \def\@mcitesublistmode{f}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehfalse\else
  197. \ifx\@mcitetemp\@mciteMacroh
  198. \def\@mcitesublistmode{h}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehtrue\else
  199. \PackageError{mciteplus}{Unknown mode `#1' in argument to \protect\mciteSetSublistMode}%
  200. {Only `d', `n', `s', `b', `f' and `h' are valid.}\relax
  201. \fi
  202. \fi
  203. \fi
  204. \fi
  205. \fi
  206. \fi}
  207. % checks to see if valid type in \@mciteformtypeArg (bibitem or subitem), errors if not
  208. % #1 is name of calling macro
  209. \def\@mcitecheckformtypeerror#1{\relax
  210. \ifx\@mciteformtypeArg\@mciteMacrobibitem\relax
  211. \else
  212. \ifx\@mciteformtypeArg\@mciteMacrosubitem\relax
  213. \else
  214. \PackageError{mciteplus}{Unknown form type `\@mciteformtypeArg' in argument to \protect#1}%
  215. {Only `bibitem' and `subitem' are valid.}\relax
  216. \fi
  217. \fi}
  218. % sets the bst max width forms
  219. % usage: \mciteSetBstMaxWidthForm[init]{type}{form}
  220. % where type is bibitem or subitem
  221. % if [init] not given, uses \mcitedefaultmaxwidth[TYPE]forminit
  222. \def\mciteSetBstMaxWidthForm{\@ifnextchar[{\@mciteLocalMacroOptArgItrue\@mciteSetBstMaxWidthForm}{\@mciteLocalMacroOptArgIfalse\@mciteSetBstMaxWidthForm[\relax]}}
  223. \def\@mciteSetBstMaxWidthForm[#1]#2#3{\edef\@mciteformtypeArg{#2}\relax
  224. \@mcitecheckformtypeerror{\mciteSetBstMaxWidthForm}\relax
  225. \expandafter\def\csname mcitebstmaxwidth\@mciteformtypeArg form\endcsname{#3}\relax
  226. \if@mciteLocalMacroOptArgI
  227. \expandafter\def\csname mcitebstmaxwidth\@mciteformtypeArg forminit\endcsname{#1}\relax
  228. \else
  229. \expandafter\expandafter\expandafter\def\expandafter\expandafter\csname mcitebstmaxwidth\@mciteformtypeArg forminit\endcsname\expandafter{\csname mcitedefaultmaxwidth\@mciteformtypeArg forminit\endcsname}\relax
  230. \fi}
  231. % sets the max width forms
  232. % usage: \mciteSetMaxWidthForm[init]{type}{form}
  233. % where type is bibitem or subitem
  234. % if [init] not given, uses \mcitebstmaxwidth[TYPE]forminit
  235. \def\mciteSetMaxWidthForm{\@ifnextchar[{\@mciteLocalMacroOptArgItrue\@mciteSetMaxWidthForm}{\@mciteLocalMacroOptArgIfalse\@mciteSetMaxWidthForm[\relax]}}
  236. \def\@mciteSetMaxWidthForm[#1]#2#3{\edef\@mciteformtypeArg{#2}\relax
  237. \@mcitecheckformtypeerror{\mciteSetMaxWidthForm}\relax
  238. \expandafter\def\csname mcitemaxwidth\@mciteformtypeArg form\endcsname{#3}\relax
  239. \if@mciteLocalMacroOptArgI
  240. \expandafter\def\csname mcitemaxwidth\@mciteformtypeArg forminit\endcsname{#1}\relax
  241. \else
  242. \expandafter\expandafter\expandafter\def\expandafter\expandafter\csname mcitemaxwidth\@mciteformtypeArg forminit\endcsname\expandafter{\csname mcitebstmaxwidth\@mciteformtypeArg forminit\endcsname}\relax
  243. \fi}
  244. % initialize punctuation, sublist and maxwidth hooks
  245. %
  246. % punctuation controls
  247. % default is to hook into the bst
  248. \mciteSetMidEndSepPunct{\mcitebstmidpunct}{\mcitebstendpunct}{\mcitebstseppunct}
  249. % the default bst setting is to use the package defaults
  250. \mciteSetBstMidEndSepPunct{\mcitedefaultmidpunct}{\mcitedefaultendpunct}{\mcitedefaultseppunct}
  251. %
  252. % sublist controls
  253. % default sublist mode is to use the defaults
  254. \mciteSetBstSublistMode{d}
  255. \mciteSetSublistMode{d}
  256. % the default sublabel bst setting is to use the package defaults
  257. \mciteSetBstSublistLabelBeginEnd{\mcitedefaultsublistlabel}{\mcitedefaultsublistbegin}{\mcitedefaultsublistend}
  258. % default sublabel setting is to hook into the bst settings
  259. \mciteSetSublistLabelBeginEnd{\mcitebstsublistlabel}{\mcitebstsublistbegin}{\mcitebstsublistend}
  260. %
  261. % max width form controls
  262. % the default max width form bst settings is to use the package defaults
  263. \mciteSetBstMaxWidthForm[\mcitedefaultmaxwidthbibitemforminit]{bibitem}{\mcitedefaultmaxwidthbibitemform}
  264. \mciteSetBstMaxWidthForm[\mcitedefaultmaxwidthsubitemforminit]{subitem}{\mcitedefaultmaxwidthsubitemform}
  265. % the default max width form settings is to hook into the bst settings
  266. \mciteSetMaxWidthForm[\mcitebstmaxwidthbibitemforminit]{bibitem}{\mcitebstmaxwidthbibitemform}
  267. \mciteSetMaxWidthForm[\mcitebstmaxwidthsubitemforminit]{subitem}{\mcitebstmaxwidthsubitemform}
  268. % Defines a macro to track the status of entries. An example showing the
  269. % format is \@mciteEntryStatus@1@Smith98
  270. % where the 1 is the tracking ID, and Smith98 is the cite key.
  271. % Possible values for this status macro are:
  272. % 0 = not yet determined
  273. % 1 = tail (tail entry following a head entry)
  274. % 2 = head (head entry followed by one or more tails)
  275. % 3 = single (head entry not followed by any tails)
  276. % usage: \@mciteSetEntryStatus{track ID}{cite key}{status}
  277. \def\@mciteSetEntryStatus#1#2#3{\expandafter\xdef\csname @mciteEntryStatus@#1@#2\endcsname{#3}\relax
  278. %\typeout{SetEntryStatus: Track:`#1' Key:`#2' Status:`#3'}\relax
  279. }
  280. % used to obtain status of a given cite key
  281. % usage: \@mciteGetEntryStatus*{track ID}{cite key}{status out}
  282. % star form: no error checking
  283. \def\@mciteGetEntryStatus{\@ifstar{\@mciteGetEntryStatusStar}{\@mciteGetEntryStatusNoStar}}
  284. \def\@mciteGetEntryStatusStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteEntryStatus@#1@#2\endcsname}
  285. \def\@mciteGetEntryStatusNoStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteEntryStatus@#1@#2\endcsname\relax
  286. \ifx#3\relax
  287. \ifmciteErrorOnUnknown
  288. \PackageError{mciteplus}{Entry Status for cite key `#2' under tracking ID `#1' is undefined, treating it as a head entry}{I don't have a
  289. record of the head/tail status of this citation. Possible reasons include the use
  290. of a cite command that is not mciteplus aware, the use of `\string\nocite{*}', or a problem with the
  291. tracking ID and/or aux file handles. `\string\mciteErrorOnUnknownfalse' can be used to disable this error message.}\relax
  292. \fi
  293. \expandafter\def#3{3}\relax
  294. \fi}
  295. % set head key for given tail
  296. % usage: \@mciteSetHeadofTail{track ID}{tail cite key}{head cite key}
  297. \def\@mciteSetHeadofTail#1#2#3{\expandafter\xdef\csname @mciteHeadofTail@#1@#2\endcsname{#3}}
  298. % get head key for given tail
  299. % usage: \@mciteGetHeadofTail{track ID}{tail cite key}{head key out}
  300. % star form: no error checking
  301. \def\@mciteGetHeadofTail{\@ifstar{\@mciteGetHeadofTailStar}{\@mciteGetHeadofTailNoStar}}
  302. \def\@mciteGetHeadofTailStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteHeadofTail@#1@#2\endcsname}
  303. \def\@mciteGetHeadofTailNoStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteHeadofTail@#1@#2\endcsname\relax
  304. \ifx#3\relax
  305. \PackageError{mciteplus}{Head for tail cite key `#2' under tracking ID `#1' is undefined}{I don't have a
  306. record of the head key of this citation.}\relax
  307. \fi}
  308. % for debug status messages
  309. % converts given status number to word description
  310. \def\@mciteStatusNumToWord#1{\expandafter\ifcase#1\relax
  311. Unknown\or Tail\or Head with tails\or Head without tails\else Invalid (#1)\fi}
  312. % form that makes no distinction between status 2 or 3. Used with \cite debug as
  313. % head status is not finalized till after the entry group
  314. \def\@mciteStatusNumToWordH#1{\expandafter\ifcase#1\relax
  315. Unknown\or Tail\or Head\or Head\else Invalid (#1)\fi}
  316. % usage:\mciteSetMaxWidth{track ID}{type}{width}
  317. % Defines a macro to track the max width of a given label type.
  318. % An example showing the format is \@mciteMaxWidthStore@main@bibitem
  319. % which is set globally
  320. % we don't use @ in the macro name as this cmd appears in the aux
  321. \def\mciteSetMaxWidth#1#2#3{\edef\@mciteformtypeArg{#2}\relax
  322. \@mcitecheckformtypeerror{\mciteSetMaxWidth}\relax
  323. \expandafter\xdef\csname @mciteMaxWidthStore@#1@\@mciteformtypeArg\endcsname{#3}}
  324. %
  325. % usage:\mciteGetMaxWidth{track ID}{type}{out macro}
  326. % reads the stored max width of the given label type into the out macro
  327. % which is set globally
  328. \def\mciteGetMaxWidth#1#2#3{\edef\@mciteformtypeArg{#2}\relax
  329. \@mcitecheckformtypeerror{\mciteGetMaxWidth}\relax
  330. \expandafter\global\expandafter\let\expandafter#3\csname @mciteMaxWidthStore@#1@\@mciteformtypeArg\endcsname}
  331. % usage:\mciteSetMaxCount{track ID}{type}{count}
  332. % Defines a macro to track the max count of a given label type.
  333. % An example showing the format is \@mciteMaxCountStore@main@bibitem
  334. % which is set globally
  335. % we don't use @ in the macro name as this cmd appears in the aux
  336. \def\mciteSetMaxCount#1#2#3{\edef\@mciteformtypeArg{#2}\relax
  337. \@mcitecheckformtypeerror{\mciteSetMaxCount}\relax
  338. \expandafter\xdef\csname @mciteMaxCountStore@#1@\@mciteformtypeArg\endcsname{#3}}
  339. %
  340. % usage:\mciteGetMaxCount{track ID}{type}{out macro}
  341. % reads the stored max count of the given label type into the out macro
  342. % which is set globally
  343. \def\mciteGetMaxCount#1#2#3{\edef\@mciteformtypeArg{#2}\relax
  344. \@mcitecheckformtypeerror{\mciteGetMaxCount}\relax
  345. \expandafter\global\expandafter\let\expandafter#3\csname @mciteMaxCountStore@#1@\@mciteformtypeArg\endcsname}
  346. % sets \mcitemaxcountbibitem and \mcitemaxcountsubitem via \mciteGetMaxCount globally
  347. % sets them to zero if \mciteGetMaxCount returns \relax
  348. % clears \@mcitecorrectmaxcountbibitem and \@mcitecorrectmaxcountsubitem
  349. % uses \@mcitecurtrackID
  350. \def\@mciteMaxCountInitialize{\mciteGetMaxCount{\@mcitecurtrackID}{bibitem}{\mcitemaxcountbibitem}\relax
  351. \ifx\mcitemaxcountbibitem\relax\gdef\mcitemaxcountbibitem{0}\fi
  352. \mciteGetMaxCount{\@mcitecurtrackID}{subitem}{\mcitemaxcountsubitem}\relax
  353. \ifx\mcitemaxcountsubitem\relax\gdef\mcitemaxcountsubitem{0}\fi
  354. \global\let\mcitemaxcountbibitem\mcitemaxcountbibitem
  355. \global\let\mcitemaxcountsubitem\mcitemaxcountsubitem
  356. \xdef\@mcitecorrectmaxcountbibitem{0}\relax
  357. \xdef\@mcitecorrectmaxcountsubitem{0}\relax}
  358. %
  359. % usage: \@mciteMaxCountUpdate
  360. % updates \@mcitecorrectmaxcountsubitem
  361. % no need for \@mcitecorrectmaxcountbibitem as this is carried by the counter itself
  362. \def\@mciteMaxCountUpdate{\relax
  363. \ifnum\@mcitecorrectmaxcountsubitem<\arabic{mcitesubitemcount}\relax
  364. \xdef\@mcitecorrectmaxcountsubitem{\arabic{mcitesubitemcount}}\relax
  365. \fi}
  366. %
  367. % usage: \@mciteMaxCountAuxWrite uses \@mcitecurauxout and \@mcitecurtrackID
  368. % writes \mciteSetMaxCount{track ID}{type}{count} to \@mcitecurauxout
  369. % and warns if correct values do not match \mcitemaxcountbibitem, \mcitemaxcountsubitem
  370. \def\@mciteMaxCountAuxWrite{\relax
  371. \if@filesw
  372. \immediate\write\@mcitecurauxout{\string\mciteSetMaxCount{\@mcitecurtrackID}{bibitem}{\arabic{mcitebibitemcount}}}\relax
  373. \immediate\write\@mcitecurauxout{\string\mciteSetMaxCount{\@mcitecurtrackID}{subitem}{\@mcitecorrectmaxcountsubitem}}\relax
  374. \fi
  375. \ifnum\mcitemaxcountbibitem=\arabic{mcitebibitemcount}\relax
  376. \ifnum\mcitemaxcountsubitem=\@mcitecorrectmaxcountsubitem\relax\else
  377. \@latex@warning@no@line{Mciteplus max count has changed}\global\@mciteLaTeXreruntrue
  378. \fi
  379. \else
  380. \@latex@warning@no@line{Mciteplus max count has changed}\global\@mciteLaTeXreruntrue
  381. \fi}
  382. % usage: \@mciteMaxWidthInitialize{type}
  383. % sets \mcitemaxwidth[TYPE] via \GetMaxWidth globally
  384. % if \GetMaxWidth returns \relax, sets them to the width (without sp units at end) of \mcitebstmaxwidth[TYPE]forminit
  385. % as evaluated when bibitem and subitem counters are both = 1
  386. % clears \@mcitecorrectmaxwidth[TYPE] globally to 0
  387. % uses \@mcitecurtrackID
  388. \def\@mciteMaxWidthInitialize#1{\edef\@mcitemaxwidthinitializetypeArg{#1}\relax
  389. \expandafter\mciteGetMaxWidth\expandafter{\expandafter\@mcitecurtrackID\expandafter}\expandafter{\expandafter\@mcitemaxwidthinitializetypeArg\expandafter}\expandafter{\csname mcitemaxwidth#1\endcsname}\relax
  390. \expandafter\ifx\csname mcitemaxwidth#1\endcsname\relax
  391. \begingroup
  392. % set counters to 1 locally
  393. \csname c@mcitebibitemcount\endcsname 1\relax
  394. \csname c@mcitesubitemcount\endcsname 1\relax
  395. \settowidth{\@mcitetmpdima}{\csname mcitemaxwidth#1forminit\endcsname}\relax
  396. \@mcitetmpcnta=\@mcitetmpdima\relax
  397. \expandafter\xdef\csname mcitemaxwidth#1\endcsname{\the\@mcitetmpcnta}\relax
  398. \endgroup
  399. \fi
  400. \expandafter\xdef\csname @mcitecorrectmaxwidth#1\endcsname{0}}
  401. %
  402. % usage: \@mciteMaxWidthUpdate{type}
  403. % globally updates \@mcitecorrectmaxwidth[TYPE] based on \mcitemaxwidth[TYPE]form
  404. \def\@mciteMaxWidthUpdate#1{\relax
  405. \settowidth{\@mcitetmpdima}{\csname mcitemaxwidth#1form\endcsname}\relax
  406. \@mcitetmpcnta=\@mcitetmpdima\relax
  407. \@mcitetmpcntb=\csname @mcitecorrectmaxwidth#1\endcsname\relax
  408. \ifnum\@mcitetmpcnta>\@mcitetmpcntb\relax
  409. \expandafter\xdef\csname @mcitecorrectmaxwidth#1\endcsname{\the\@mcitetmpcnta}\relax
  410. \fi}
  411. %
  412. %
  413. % usage: \@mciteMaxWidthAuxWrite uses \@mcitecurauxout and \@mcitecurtrackID
  414. % writes \mciteSetMaxWidth{track ID}{type}{correct width in sp}
  415. % for both bibitem and subitem to \@mcitecurauxout
  416. % and warns if correct values do not match \mcitemaxwidthbibitem, \mcitemaxwidthsubitem
  417. \def\@mciteMaxWidthAuxWrite{\relax
  418. \if@filesw
  419. \immediate\write\@mcitecurauxout{\string\mciteSetMaxWidth{\@mcitecurtrackID}{bibitem}{\@mcitecorrectmaxwidthbibitem}}\relax
  420. \immediate\write\@mcitecurauxout{\string\mciteSetMaxWidth{\@mcitecurtrackID}{subitem}{\@mcitecorrectmaxwidthsubitem}}\relax
  421. \fi
  422. \ifnum\mcitemaxwidthbibitem=\@mcitecorrectmaxwidthbibitem\relax
  423. \ifnum\mcitemaxwidthsubitem=\@mcitecorrectmaxwidthsubitem\relax\else
  424. \@latex@warning@no@line{Mciteplus max width has changed}\global\@mciteLaTeXreruntrue
  425. \fi
  426. \else
  427. \@latex@warning@no@line{Mciteplus max width has changed}\global\@mciteLaTeXreruntrue
  428. \fi}
  429. % empty \mciteheadlist in case someone trys to access it before a \cite
  430. \def\mciteheadlist{}
  431. % default wrappers for \cite and \nocite, package hooks (e.g., multibbl) can change these later
  432. \def\@mciteCiteWrapper{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgcite}}
  433. \def\@mciteNociteWrapper{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgnocite}}
  434. % \mcite was undocumented in mcite.sty. We don't need it and it will not work with
  435. % some multibibliography packages. So, we'll not use them.
  436. % mcite version of \cite
  437. %\def\mcite{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgcite}}
  438. % mcite version of \nocite
  439. %\def\mnocite{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgnocite}}
  440. % mciteplus \cite wrappers
  441. % usage: \mciteCiteA*{aux out}{track ID}{prehandler}{posthandler}{fwd macro}*[opt1][opt2]{cite list}
  442. % \mciteCiteB*{aux out}{track ID}{prehandler}{posthandler}{fwd macro}*[opt1][opt2]{sec ID}{cite list}
  443. % B form is for \cite that use two arguments, such as that of multibbl.sty
  444. % processes cite list and fowards arguments and list of heads to specified \cite macro
  445. % star form means no default \mciteDoList processing
  446. \DeclareRobustCommand{\mciteCiteA}{\@mciteCiteSecIDArgfalse\@mciteCiteAB}
  447. \DeclareRobustCommand{\mciteCiteB}{\@mciteCiteSecIDArgtrue\@mciteCiteAB}
  448. \def\@mciteCiteAB{\@ifstar{\mciteMacroStarFormtrue\@@mciteCiteAB}{\mciteMacroStarFormfalse\@@mciteCiteAB}}
  449. \def\@@mciteCiteAB#1#2#3#4#5{\def\mciteCiteAuxArg{#1}\def\mciteCiteTrackArg{#2}\def\mciteCitePrehandlerArg{#3}\relax
  450. \def\mciteCitePosthandlerArg{#4}\relax\def\mciteCiteFwdArg{#5}\relax
  451. \@ifstar{\mciteCiteStarFwdArgtrue\@@@mciteCiteAB}{\mciteCiteStarFwdArgfalse\@@@mciteCiteAB}}
  452. \def\@@@mciteCiteAB{\@ifnextchar[{\mciteMacroOptArgItrue\@@@@mciteCiteAB}%
  453. {\mciteMacroOptArgIfalse\@@@@mciteCiteAB[\relax]}}
  454. \def\@@@@mciteCiteAB[#1]{\def\mciteCiteOptArgI{#1}\relax
  455. \@ifnextchar[{\mciteMacroOptArgIItrue\@@@@@mciteCiteAB}%
  456. {\mciteMacroOptArgIIfalse\@@@@@mciteCiteAB[\relax]}}
  457. \def\@@@@@mciteCiteAB[#1]{\def\mciteCiteOptArgII{#1}\relax
  458. \if@mciteCiteSecIDArg
  459. \def\@mciteNextMacroChain{\@@@@@mciteCiteB}\relax
  460. \else
  461. \let\mciteCiteSecIDArg\relax
  462. \def\@mciteNextMacroChain{\@@@@@@mciteCiteAB}\relax
  463. \fi
  464. \@mciteNextMacroChain}
  465. \def\@@@@@mciteCiteB#1{\def\mciteCiteSecIDArg{#1}\@@@@@@mciteCiteAB}
  466. \def\@@@@@@mciteCiteAB#1{\def\mciteCiteListArg{#1}\relax
  467. \edef\mciteFwdCiteListArg{}\relax
  468. % execute the user's pre-handler code
  469. \mciteCitePrehandlerArg\relax
  470. \ifmciteMacroStarForm
  471. % star form means no mcite default processing
  472. % the user will have to do all of this in their handler
  473. \else
  474. % otherwise, process the cite list and set the forward cite list to the list of heads
  475. \mciteDoList{\mciteCiteAuxArg}{\mciteCiteTrackArg}{\mciteCiteListArg}\relax
  476. \edef\mciteFwdCiteListArg{\mciteheadlist}\relax
  477. % optional additional calls to do lists for duplicate/global bibliographies
  478. \mciteExtraDoLists\relax
  479. \fi
  480. \relax
  481. % execute the user's post-handler code
  482. \mciteCitePosthandlerArg\relax
  483. % build the forwarding macro and arguments list
  484. \@mcitetmptoksA=\expandafter{\mciteCiteFwdArg}\relax
  485. \ifmciteCiteStarFwdArg
  486. \@mciteAppendToTmpToksA{*}\relax
  487. \fi
  488. \ifmciteMacroOptArgI
  489. \@mciteAppendToTmpToksA{[}\relax
  490. \expandafter\@mciteAppendToTmpToksA\expandafter{\mciteCiteOptArgI}\relax
  491. \@mciteAppendToTmpToksA{]}\relax
  492. \fi
  493. \ifmciteMacroOptArgII
  494. \@mciteAppendToTmpToksA{[}\relax
  495. \expandafter\@mciteAppendToTmpToksA\expandafter{\mciteCiteOptArgII}\relax
  496. \@mciteAppendToTmpToksA{]}\relax
  497. \fi
  498. \if@mciteCiteSecIDArg
  499. \expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\mciteCiteSecIDArg}}\relax
  500. \fi
  501. \expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\mciteFwdCiteListArg}}\relax
  502. \edef\@mciteCiteFwd{\the\@mcitetmptoksA}\relax
  503. % forward to the "real" \cite
  504. \@mciteCiteFwd}
  505. % mciteplus engine
  506. % processes cite list, records status of keys and writes tail (and head)
  507. % citations to aux file
  508. % list of heads is output to \mciteheadlist for forwarding to \cite
  509. % usage: \mciteDoList{aux out}{track ID}{cite list}
  510. % use noauxwrite for aux out to disable writes to aux
  511. \def\mciteDoList#1#2#3{\edef\@mcitecurauxout{#1}\edef\@mcitecurtrackID{#2}\edef\@mcitetemp{#3}\relax
  512. \expandafter\@mciteDoList\expandafter{\@mcitetemp}}
  513. % flag to determine if mciteDoList should write to aux file
  514. \newif\if@mciteDoListwriteaux \@mciteDoListwriteauxtrue
  515. \def\@mciteMacronoauxwrite{noauxwrite}
  516. \def\@mciteDoList#1{\let\@mcitecurhead\relax % reset current head
  517. \@mciteDoListwriteauxtrue
  518. % disable aux writes if aux parameter is "noauxwrite"
  519. \ifx\@mcitecurauxout\@mciteMacronoauxwrite\@mciteDoListwriteauxfalse\fi
  520. \@mcitefirstentrytrue\@mcitefirstheadentrytrue
  521. \def\mciteheadlist{}\def\@mcitecurstatus{\relax}\relax
  522. \@for\@mcitecurkey:=#1\do{\expandafter\@mciteCheckKey\@mcitecurkey\end\relax
  523. % ignore empty keys
  524. \ifx\@mcitecurkey\@empty
  525. % warn about \nocite{*}
  526. \if@mcitestarentry
  527. \typeout{** WARNING: mciteplus: Wildcard `*' citation entry declared. BibTeX will add untracked entries to the bibliography.}\relax
  528. % add * to the head list
  529. \if@mcitefirstentry
  530. \@mcitefirstentryfalse
  531. \edef\mciteheadlist{*}\relax
  532. \else
  533. \edef\mciteheadlist{\mciteheadlist,*}\relax
  534. \fi
  535. \fi
  536. \else % key is not empty
  537. % get entry status
  538. \@mciteGetEntryStatus*{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
  539. % if entry status is undefined, set status number code to undetermined and update \@mcitecurstatus
  540. \ifx\@mcitecurstatus\relax
  541. \@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{0}\relax
  542. \@mciteGetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
  543. \fi
  544. \if@mcitestarentry % if declared to be a tail
  545. \if@mcitefirstheadentry % tail cannot be declared until after a head
  546. \PackageError{mciteplus}{Tail `\@mcitecurkey' is declared without a valid head}{You have to
  547. declare a head citation before entering tail citations in cite list.}\relax
  548. \fi
  549. \ifnum\@mcitecurstatus>1\relax % cannot have been previously declared as a head
  550. \PackageError{mciteplus}{Tail citation `\@mcitecurkey' has previously been declared as a head}{Declare
  551. each citation entry as a head or a tail, but not both.}\relax
  552. \fi
  553. \if@mciteheadredeclared % the current head has been redeclared, OK with some restrictions
  554. \ifnum\@mcitecurstatus=0\relax % cannot add new tails to previous group definitions
  555. \PackageError{mciteplus}{New tail citation `\@mcitecurkey' cannot be added to the already existing
  556. definition of group of head `\@mcitecurhead'}{You cannot define a group,
  557. then reissue the head and add new tail citations.}\relax
  558. \fi
  559. \ifnum\@mcitecurstatus=1\relax % OK to respecify tails as long as they already belong to this group,
  560. % this allows for overall (global) bibliographies
  561. \@mciteGetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mciteheadofcurkey}\relax
  562. \ifx\@mciteheadofcurkey\@mcitecurhead
  563. % Note: We don't/can't catch the case of repeated tail declarations under a redeclared head.
  564. % Not a mandatory error anyway.
  565. \else
  566. % tail cannot have been declared in definition of another group
  567. \PackageError{mciteplus}{Tail citation `\@mcitecurkey' is not allowed in group of head
  568. `\@mcitecurhead' as this tail has already been declared in group
  569. of head `\@mciteheadofcurkey'}{You cannot have a tail citation
  570. that appears in more than one citation group.}\relax
  571. \fi
  572. \fi
  573. \else % head not redeclared
  574. \ifnum\@mcitecurstatus=1\relax % the current head has not been declared before, so neither should any of its tails
  575. \@mciteGetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mciteheadofcurkey}\relax
  576. \ifx\@mciteheadofcurkey\@mcitecurhead
  577. % tail cannot be declared twice in initial definition, this is an optional error
  578. \PackageError{mciteplus}{Tail citation `\@mcitecurkey' has been declared more than once in
  579. definition of group for head `\@mcitecurhead'}{Each tail
  580. citation can only be specified once in the definition
  581. of a group.}\relax
  582. \else
  583. % tail cannot have been declared in definition of another group
  584. \PackageError{mciteplus}{Tail citation `\@mcitecurkey' is not allowed in group of head
  585. `\@mcitecurhead' as this tail has already been declared in group
  586. of head `\@mciteheadofcurkey'}{You cannot have a tail citation
  587. that appears in more than one citation group.}\relax
  588. \fi
  589. \fi
  590. \fi% end if head redeclared
  591. % if not declared before, process as a valid tail
  592. \ifnum\@mcitecurstatus=0\relax
  593. % record type as tail
  594. \@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{1}\relax
  595. \@mciteGetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
  596. % write out tail citation to aux as it will not be forwarded to \cite
  597. \if@mciteDoListwriteaux
  598. \@mcitewritecurkeytoaux
  599. \fi
  600. % record head for this tail
  601. \@mciteSetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurhead}\relax
  602. % change current head from code 3 (single) to 2 (one or more tails)
  603. \@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurhead}{2}\relax
  604. \fi
  605. \else % is declared to be a head
  606. \edef\@mcitecurhead{\@mcitecurkey}\relax % this is our new current head
  607. % add to the head list
  608. \if@mcitefirstentry
  609. \@mcitefirstentryfalse
  610. \edef\mciteheadlist{\@mcitecurkey}\relax
  611. \else
  612. \edef\mciteheadlist{\mciteheadlist,\@mcitecurkey}\relax
  613. \fi
  614. \@mcitefirstheadentryfalse
  615. \ifnum\@mcitecurstatus=1\relax % cannot have previously been used as a tail
  616. \@mciteGetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mciteheadofcurkey}\relax
  617. \PackageError{mciteplus}{Head citation `\@mcitecurkey' has previously been declared
  618. as a tail of `\@mciteheadofcurkey'}{Declare each citation
  619. entry as a head or a tail, but not both.}\relax
  620. \fi
  621. \@mciteheadredeclaredfalse % assume not redeclared
  622. \ifnum\@mcitecurstatus>1\relax % has already been declared?
  623. \@mciteheadredeclaredtrue % OK, but do not allow any new future tails for this head
  624. \fi
  625. % if not declared before, set as a head, single. Will later change to code 2 if tails are found.
  626. \if@mciteheadredeclared\else
  627. \@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{3}\relax
  628. \@mciteGetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
  629. % write out head citation to aux.
  630. % This will result in the entry appearing twice in the aux file as the
  631. % entry will be part of the \mciteheadlist which will be forwarded to \cite.
  632. % However, we need to write this out now to preserve the order of the citations.
  633. \if@mciteDoListwriteaux
  634. \@mcitewritecurkeytoaux
  635. \fi
  636. % this is the new current head
  637. \let\@mcitecurhead\@mcitecurkey
  638. \fi % fi not headredeclared
  639. \fi % fi tail or head
  640. % debug report
  641. \if@OPTIONmcitedebug
  642. \ifnum\@mcitecurstatus=1\relax
  643. \edef\@mcitedebugheadoftail{Head of this tail: `\@mcitecurhead'}\relax
  644. \else
  645. \edef\@mcitedebugheadoftail{}\relax
  646. \fi
  647. \typeout{** Mciteplus Debug: Citation Entry: `\@mcitecurkey' TrackID: `\@mcitecurtrackID'
  648. Auxout: \ifx\@mcitecurauxout\@mciteMacronoauxwrite `none (\@mciteMacronoauxwrite)' \else `\the\@mcitecurauxout' \fi
  649. Status: `\@mciteStatusNumToWordH{\@mcitecurstatus}' \@mcitedebugheadoftail}\relax
  650. \fi
  651. % end debug report
  652. \fi % only nonempty
  653. }% end do loop
  654. }
  655. % hook to allow for a redo. Useful for global bibliographies
  656. \def\mciteExtraDoLists{\relax}
  657. % determines if an entry starts with an *, removes the * from the start of the entry name
  658. % and sets \@mcitestarentry and \@mcitecurkey accordingly
  659. \def\@mciteCheckKey#1#2\end{\@mcitestarentryfalse
  660. \ifx*#1\@mcitestarentrytrue\edef\@mcitecurkey{#2}\relax
  661. \else
  662. \edef\@mcitecurkey{#1#2}%
  663. \fi}
  664. % writes current key citation to aux. We put this in a macro because some packages
  665. % may fiddle with \if@filesw (making it a macro rather than an if), tripping up
  666. % TeX's parser if \if@filesw is ever within another conditional as is the case
  667. % within \@mciteDoList
  668. \def\@mcitewritecurkeytoaux{\if@filesw\immediate\write\@mcitecurauxout{\string\citation{\@mcitecurkey}}\fi}
  669. % custom \ref command displays \mcitesubrefform when
  670. % \ref'd
  671. % prefix to reference labels to avoid namespace clash
  672. \def\@mcitereflabelprefix{MciteSubReferenceLabel}
  673. \def\@mciteSetSubRefLabel{\begingroup\def\@currentlabel{\mcitesubrefform}\label{\@mcitereflabelprefix:\@mcitecurtrackID:\mciteBibitemArgI}\endgroup}
  674. % default to using the actual sublist form.
  675. \providecommand{\mcitesubrefform}{\arabic{mcitebibitemcount}.\alph{mcitesubitemcount}}
  676. % give user access to sublist \ref and \pageref
  677. % usage: \mciteSubRef[track ID]{cite key}
  678. \def\mciteSubRef{\@ifnextchar[{\@mciteSubRef}{\@mciteSubRef[\mcitetrackID]}}
  679. \def\@mciteSubRef[#1]#2{\ref{\@mcitereflabelprefix:#1:#2}}
  680. \def\mciteSubPageRef{\@ifnextchar[{\@mciteSubPageRef}{\@mciteSubPageRef[\mcitetrackID]}}
  681. \def\@mciteSubPageRef[#1]#2{\pageref{\@mcitereflabelprefix:#1:#2}}
  682. % for debug, head of tail lookup
  683. \def\@mcitecurheadlookup{}
  684. % mciteplus version of \bibitem
  685. % support the optional arg of \bibitem[]{} as well
  686. \def\mcitebibitem{\@ifnextchar[{\global\mciteBibitemOptArgItrue\@mcitebibitem}%
  687. {\global\mciteBibitemOptArgIfalse\@mcitebibitem[\relax]}}
  688. \def\@mcitebibitem[#1]#2{\relax
  689. % build the forwarding macro: \mciteOrgbibitem{#2} or \mciteOrgbibitem[#1]{#2}
  690. \gdef\mciteBibitemOptArgI{#1}\gdef\mciteBibitemArgI{#2}\relax
  691. \@mcitetmptoksA={\mciteOrgbibitem}\relax
  692. \ifmciteBibitemOptArgI
  693. \@mciteAppendToTmpToksA{[}\relax
  694. \expandafter\@mciteAppendToTmpToksA\expandafter{\mciteBibitemOptArgI}\relax
  695. \@mciteAppendToTmpToksA{]}\relax
  696. \fi
  697. \expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\mciteBibitemArgI}}\relax
  698. % build the command. we need a global def here so that the changes will persist in spite
  699. % of a later closed sublist
  700. \xdef\@mciteBibitemFwdMacroArgs{\the\@mcitetmptoksA}\relax
  701. % on the very first \bibitem initialize the maxwidths
  702. % we do this here so that the bibstyle can have its say on the forminit
  703. \if@mcitefirstentry
  704. \@mciteMaxWidthInitialize{bibitem}\relax
  705. \@mciteMaxWidthInitialize{subitem}\relax
  706. \fi
  707. % get status of entry and process accordingly
  708. \@mciteGetEntryStatus{\@mcitecurtrackID}{#2}{\@mcitecurstatus}\relax
  709. % status get may happen inside a list, so make the changes to \@mcitecurstatus global
  710. \global\let\@mcitecurstatus\@mcitecurstatus
  711. % debug report
  712. \if@OPTIONmcitedebug
  713. \ifnum\@mcitecurstatus=1\relax
  714. \@mciteGetHeadofTail{\@mcitecurtrackID}{\mciteBibitemArgI}{\@mcitecurheadlookup}\relax
  715. \edef\@mcitedebugheadoftail{Head of this tail: `\@mcitecurheadlookup' (from citation), `\@mcitecurhead' (in bibliography)}\relax
  716. \else
  717. \edef\@mcitedebugheadoftail{}\relax
  718. \fi
  719. \typeout{** Mciteplus Debug: \string\mcitebibitem\space Entry: `\mciteBibitemArgI' TrackID: `\@mcitecurtrackID'
  720. Status: `\@mciteStatusNumToWord{\@mcitecurstatus}' \@mcitedebugheadoftail}\relax
  721. \fi
  722. % end debug report
  723. \ifnum\@mcitecurstatus=1\relax % if a tail
  724. % error if a tail starts the bibliography
  725. \if@mcitefirstentry
  726. \PackageError{mciteplus}{Bibliography begins with a tail entry `\mciteBibitemArgI'}{For sorting
  727. bibstyles, you must set the `mcitetail' BibTeX database field
  728. for each tail entry and use a bibstyle that understands that field.}\relax
  729. \fi
  730. \mcitemidpunct\relax
  731. % open sublist if needed
  732. \if@mcitesublistmode
  733. \if@mcitesublistopen\else
  734. \global\@mcitesublistopentrue
  735. \relax\mcitesublistbegin\relax
  736. \fi
  737. \relax\mcitesublistlabel\relax\@mciteSetSubRefLabel\relax\@mciteMaxWidthUpdate{subitem}\relax
  738. \fi
  739. \@mciteMaxCountUpdate
  740. \addtocounter{mcitesubitemcount}{1}\relax
  741. \else% is head
  742. \if@mcitefirstentry\else\mciteendpunct\relax\mciteEndOfBibGroupPresubcloseHook\relax\fi
  743. % close sublist if open
  744. % watch out with variables as this will close off local changes
  745. % addtocounter and setcounter make global changes
  746. \if@mcitesublistopen
  747. \mcitesublistend\relax
  748. \global\@mcitesublistopenfalse
  749. \fi
  750. \relax\mciteEndOfBibGroupPostsubcloseHook\relax
  751. % record current head key and argument info
  752. \xdef\@mcitecurhead{#2}\relax
  753. \gdef\mciteCurheadBibitemArgI{#2}\relax
  754. \gdef\mciteCurheadBibitemOptArgI{#1}\relax
  755. \ifmciteBibitemOptArgI\global\mciteCurheadBibitemOptArgItrue\else\global\mciteCurheadBibitemOptArgIfalse\fi
  756. % note: with \mcitebibitem mcitebibitemcount advances with heads
  757. % and holds the current head count until the next \mcitebibitem
  758. % However, at the end of the \mcitebibitem, mcitesubitemcount
  759. % is one more than the number of subitems as the label is
  760. % rendered before updating the counter.
  761. \setcounter{mcitesubitemcount}{1}\relax
  762. \addtocounter{mcitebibitemcount}{1}\relax
  763. \@mciteMaxCountUpdate
  764. \if@mcitefirstentry\else\relax\mciteseppunct\relax\fi
  765. \@mciteBibitemFwdMacroArgs\relax\relax\relax
  766. % check and update the bibitem label width
  767. \@mciteMaxWidthUpdate{bibitem}\relax
  768. \ifnum\@mcitecurstatus=2\relax % if head with tails
  769. \if@mcitesublistmodef
  770. % open sublist if needed
  771. \if@mcitesublistopen\else
  772. \global\@mcitesublistopentrue
  773. \mcitesublistbegin\relax
  774. \fi
  775. \relax\mcitesublistlabel\relax\@mciteSetSubRefLabel\relax\@mciteMaxWidthUpdate{subitem}\relax
  776. \addtocounter{mcitesubitemcount}{1}\relax
  777. \fi
  778. \fi
  779. \ifnum\@mcitecurstatus=3\relax % if head without tails
  780. \if@mcitesublistmodeh
  781. % open sublist if needed
  782. \if@mcitesublistopen\else
  783. \global\@mcitesublistopentrue
  784. \mcitesublistbegin\relax
  785. \fi
  786. \relax\mcitesublistlabel\relax\@mciteSetSubRefLabel\relax\@mciteMaxWidthUpdate{subitem}\relax
  787. \addtocounter{mcitesubitemcount}{1}\relax
  788. \fi
  789. \fi
  790. \if@mcitesublistmodeb
  791. \addtocounter{mcitesubitemcount}{1}\relax
  792. \fi
  793. \fi% if tail or head
  794. \global\@mcitefirstentryfalse\ignorespaces}
  795. % End of \bibitem marker from bibstyle
  796. \def\EndOfBibitem{\relax}
  797. % hook inserted at the end of bibitem group, before the sublist is closed
  798. \def\mciteEndOfBibGroupPresubcloseHook{\relax}
  799. % hook inserted at the end of bibitem group, after the sublist is closed
  800. \def\mciteEndOfBibGroupPostsubcloseHook{\relax}
  801. % hook inserted at \mcitethebibliography
  802. \def\mcitethebibliographyHook{\relax}
  803. % hook to allow insertion of custom code at end of mcitethebibliography
  804. \def\mciteBIBdecl{\relax}
  805. % hook to allow insertion of custom code at end of endmcitethebibliography
  806. \def\mciteBIBenddecl{\relax}
  807. % hook to allow insertion of custom code at end of thebibliography
  808. \def\mcitefwdBIBdecl{\relax}
  809. % Bibdecl for package hooks
  810. \def\@mcitepkgBIBdecl{\relax}
  811. % single use internal BIB hook, is automatically reset to \relax at end of \mcitethebibliography
  812. \let\@mciteoneshotBIBdecl\relax
  813. % mciteplus version of \thebibliography
  814. \def\mcitethebibliography#1{\@mcitefirstentrytrue
  815. \@mcitesublistopenfalse
  816. \let\@mcitecurauxout\mcitebibauxout
  817. \let\@mcitecurtrackID\mcitebibtrackID
  818. \ifmciteResetBibitemCount\setcounter{mcitebibitemcount}{0}\fi
  819. \setcounter{mcitesubitemcount}{0}\relax
  820. \xdef\mciteorgbibsamplelabel{#1}\relax
  821. % set these to something so that init forms that reference them won't choke
  822. \gdef\mciteBibitemOptArgI{\relax}\relax
  823. \gdef\mciteBibitemArgI{\relax}\relax
  824. \global\mciteBibitemOptArgIfalse
  825. \gdef\mciteCurheadBibitemOptArgI{\relax}\relax
  826. \gdef\mciteCurheadBibitemArgI{\relax}\relax
  827. \global\mciteCurheadBibitemOptArgIfalse
  828. % note: pkg and user hooks may update tracking ID
  829. \relax\@mcitepkgBIBdecl\relax
  830. \relax\@mciteoneshotBIBdecl\relax
  831. \relax\mciteBIBdecl\relax
  832. \@mciteMaxCountInitialize
  833. % we initialize here to get a valid \mcitemaxwidthbibitem for \mcitebibsamplelabel
  834. % but we will reinitialize again at the first \bibitem so that any BST changes can take affect
  835. \@mciteMaxWidthInitialize{bibitem}\relax
  836. % debug report
  837. \if@OPTIONmcitedebug
  838. \typeout{}\typeout{}\relax
  839. \typeout{** Mciteplus Debug: \string\mcitethebibliography\space TrackID: `\@mcitecurtrackID' Auxout: `\the\@mcitecurauxout'}\relax
  840. \fi
  841. % end debug report
  842. \thebibliography{\mcitebibsamplelabel}\relax
  843. \mcitethebibliographyHook\relax
  844. \relax\mcitefwdBIBdecl\relax
  845. \let\mciteOrgbibitem\bibitem
  846. \def\bibitem{\mcitebibitem}}
  847. \def\endmcitethebibliography{\mciteendpunct\relax
  848. \relax\mciteEndOfBibGroupPresubcloseHook\relax
  849. % close sublist if open
  850. \if@mcitesublistopen
  851. \mcitesublistend\relax
  852. \@mcitesublistopenfalse
  853. \fi
  854. \relax\mciteEndOfBibGroupPostsubcloseHook\relax
  855. \relax\mciteBIBenddecl\relax
  856. % globally clear oneshot decl
  857. \global\let\@mciteoneshotBIBdecl\relax
  858. % restore original \bibitem as some \endthebibliography tack notes at the end (e.g., REVTeX)
  859. % we'll add them to the count with mcite's counters and continue to track the bibitem width
  860. \setcounter{mcitesubitemcount}{1}\relax
  861. \def\bibitem{\addtocounter{mcitebibitemcount}{1}\@mciteMaxWidthUpdate{bibitem}\relax\mciteOrgbibitem}
  862. \endthebibliography\relax
  863. % update max count for possible \endthebibliography tack notes
  864. \@mciteMaxCountUpdate
  865. % write correct max counter to aux and warn if changed
  866. \@mciteMaxCountAuxWrite
  867. % write correct max widths to aux and warn if changed
  868. \@mciteMaxWidthAuxWrite
  869. % debug report
  870. \if@OPTIONmcitedebug
  871. \typeout{}\relax
  872. \typeout{** Mciteplus Debug: \string\endmcitethebibliography^^J
  873. Current Max bibitem count: `\mcitemaxcountbibitem'^^J
  874. Correct Max bibitem count: `\arabic{mcitebibitemcount}'^^J^^J
  875. Current Max subitem count: `\mcitemaxcountsubitem'^^J
  876. Correct Max subitem count: `\@mcitecorrectmaxcountsubitem'^^J^^J
  877. Current Max bibitem width: `\mcitemaxwidthbibitem'(sp)^^J
  878. Correct Max bibitem width: `\@mcitecorrectmaxwidthbibitem'(sp)^^J^^J
  879. Current Max subitem width: `\mcitemaxwidthsubitem'(sp)^^J
  880. Correct Max subitem width: `\@mcitecorrectmaxwidthsubitem'(sp)}^^J
  881. \fi}
  882. % warn at end if any \mcitethebibliography requires a rerun due to a max width/count change
  883. \AtEndDocument{\if@mciteLaTeXrerun\@latex@warning@no@line{Rerun to ensure correct mciteplus label max width/count}\fi}
  884. % always ensure \mciteSetMaxWidth{}{}{} and \mciteSetMaxCount{}{}{} are defined in the .aux,
  885. % lest the package be unloaded and the initial .aux still refers to it.
  886. \AtBeginDocument{\if@filesw\immediate\write\@mainaux{\string\providecommand{\string\mciteSetMaxWidth}[3]{\string\relax}}\relax
  887. \immediate\write\@mainaux{\string\providecommand{\string\mciteSetMaxCount}[3]{\string\relax}}\fi}
  888. % hook into system only after all packages have been loaded
  889. \AtBeginDocument{\let\mciteOrgcite\cite\let\mciteOrgnocite\nocite
  890. \if@OPTIONmcitenohooks\else
  891. % hook into system \cite unless user says otherwise
  892. \def\cite{\@mciteCiteWrapper}
  893. \def\nocite{\@mciteNociteWrapper}
  894. \fi}
  895. % special \if macros needed for PKG hooks
  896. % we've got to define these here to shield the \ifcontinuouslabels
  897. % and and \fi from TeX's scanner when multibib is *not* loaded
  898. % as \ifcontinuouslabels will not be defined and TeX would still
  899. % see the \fi when skipping over the code.
  900. %
  901. % multibib
  902. \def\@mciteMULTIBIBcontinuouslabelsWarn{\relax
  903. \ifmciteResetBibitemCount
  904. \ifcontinuouslabels
  905. \typeout{** WARNING: mciteplus is using \string\mciteResetBibitemCounttrue, but multibib was not invoked with `resetlabels' option.}
  906. \fi
  907. \else
  908. \ifcontinuouslabels\else
  909. \typeout{** WARNING: mciteplus is using \string\mciteResetBibitemCountfalse, but multibib was invoked with `resetlabels' option.}
  910. \fi
  911. \fi}
  912. % bibunits global copy list handler
  913. \def\@mciteBIBUNITSExtraDoListHandler{\ifglobalcitecopy
  914. \mciteDoList{\mciteauxout}{main}{\mciteCiteListArg}\relax
  915. \else
  916. \ifmciteCiteStarFwdArg
  917. \mciteDoList{\mciteauxout}{main}{\mciteCiteListArg}\relax
  918. \fi
  919. \fi}
  920. % natbib command names
  921. \def\@mciteNatbibCiteCmdList{citep,Citep,citet,Citet,citealp,Citealp,citealt,Citealt,citeauthor,Citeauthor,citeyear,citeyearpar,citepalias,citetalias}
  922. % if natbib loaded, save originals at start
  923. \expandafter\ifx\csname ver@natbib.sty\endcsname\relax\else
  924. \AtBeginDocument{\@for\@mcitecurcmdname:=\@mciteNatbibCiteCmdList\do{\relax
  925. \expandafter\let\expandafter\@mcitetmpA\csname \@mcitecurcmdname\endcsname
  926. \expandafter\let\csname mciteOrg\@mcitecurcmdname\endcsname\@mcitetmpA}}
  927. \fi
  928. % *** External Package Hooks ***
  929. \if@OPTIONmcitenohooks\else% hook into packages
  930. % *** natbib.sty hooks
  931. \expandafter\ifx\csname ver@natbib.sty\endcsname\relax\else
  932. \typeout{** mciteplus: Detected natbib.sty. Invoking hooks.}\relax
  933. \AtBeginDocument{\@for\@mcitecurcmdname:=\@mciteNatbibCiteCmdList\do{\relax
  934. % reroute original cite macro \X through \mciteCiteA
  935. % \X -> \mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgX}
  936. \expandafter\@mcitetmptoksA\expandafter=\expandafter{\csname mciteOrg\@mcitecurcmdname\endcsname}\relax
  937. \expandafter\edef\csname \@mcitecurcmdname\endcsname{\noexpand\mciteCiteA{\noexpand\mciteauxout}{\noexpand\mcitetrackID}{\relax}{\relax}{\the\@mcitetmptoksA}}\relax
  938. }}
  939. \fi % if natbib.sty detected
  940. % *** cite.sty hooks
  941. \expandafter\ifx\csname ver@cite.sty\endcsname\relax\else
  942. \typeout{** mciteplus: Detected cite.sty. Invoking hooks.}\relax
  943. \AtBeginDocument{\let\@mciteCITEOrgciten\citen
  944. \def\@mciteCITEciten{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\@mciteCITEOrgciten}}\relax
  945. % This will still work even though cite.sty routes \citex through \citen.
  946. % The double calls to mciteplus will be OK as the second call to mciteplus
  947. % will only have a head list of already defined entries and so it will do nothing
  948. % other than write the list to the aux again.
  949. % Not the most elegant approach though.
  950. \def\citen{\@mciteCITEciten}\relax
  951. % Handle the aliases as well.
  952. \def\citenum{\@mciteCITEciten}\relax
  953. \def\citeonline{\@mciteCITEciten}}
  954. \fi % if cite.sty detected
  955. % *** drftcite.sty hooks
  956. \expandafter\ifx\csname ver@drftcite.sty\endcsname\relax\else
  957. \typeout{** mciteplus: Detected drftcite.sty. Invoking hooks.}\relax
  958. \AtBeginDocument{\let\@mciteDRFTCITEOrgciten\citen
  959. \def\@mciteDRFTCITEciten{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\@mciteDRFTCITEOrgciten}}\relax
  960. % As with cite.sty, this will still work even though drftcite.sty
  961. % routes \citex through \citen.
  962. \def\citen{\@mciteDRFTCITEciten}\relax}
  963. \fi % if drftcite.sty detected
  964. % *** chapterbib hooks
  965. \expandafter\ifx\csname ver@chapterbib.sty\endcsname\relax\else
  966. \typeout{** mciteplus: Detected chapterbib.sty. Invoking hooks.}\relax
  967. % one gotcha is that LaTeX closes and reopens \@partaux so aux handle number
  968. % does not change
  969. \def\mcitetrackID{chapterbib\@currentipfile}
  970. \def\mcitebibtrackID{chapterbib\@currentipfile}
  971. % make a second set of entry status macros for the duplicate bibliographies
  972. % produced under the duplicate option. Won't hurt anything if the duplicate
  973. % bibliography is not used. Note that chapterbib uses the .bbl suffix for
  974. % \@currentipfile when reading the duplicate bibliographies.
  975. \def\mciteExtraDoLists{\mciteDoList{noauxwrite}{chapterbib\@currentipfile.bbl}{\mciteCiteListArg}\relax
  976. % create third set only when chapterbib is using the rootbib option.
  977. % We can't just write this out all the time because the rootbib option can
  978. % cause a conflict in the mciteplus status of a key if that same key is
  979. % used in different parts of the document. And we can't test for the use of
  980. % the chapterbib rootbib option because chapterbib is rerun without the
  981. % rootbib option.
  982. \if@OPTIONmcitechapterbibrootbib
  983. \mciteDoList{noauxwrite}{chapterbib\jobname}{\mciteCiteListArg}\relax
  984. \fi}
  985. \fi % if chapterbib detected
  986. % *** multibib hooks
  987. \expandafter\ifx\csname ver@multibib.sty\endcsname\relax\else
  988. \typeout{** mciteplus: Detected multibib.sty. Invoking hooks.}\relax
  989. \let\@mciteOrgMULTIBIBnewcites\newcites
  990. % internally braced \nocite with \@aux handler as needed by multibib
  991. % usage: \@mciteMULTIBIBgroupedOrgNocite{multibib section name}{cite list}
  992. \def\@mciteMULTIBIBgroupedOrgNocite#1#2{{\expandafter\let\expandafter\@auxout\csname @auxout#1\endcsname
  993. \mciteOrgnocite{#2}}}
  994. \def\@mciteMULTIBIBnewcites#1#2{\relax
  995. % forward to original \newcites and let it do its thing first
  996. \@mciteOrgMULTIBIBnewcites{#1}{#2}%
  997. % now redo some of what it did our way
  998. \@for\@mciteCurRefName:=#1\do{\relax
  999. %
  1000. % build auxout names and track ID
  1001. \edef\@mcitetempauxout{\csname @auxout\@mciteCurRefName\endcsname}\relax
  1002. \edef\@mcitetemptrackID{multibib\@mciteCurRefName}\relax
  1003. %
  1004. % reroute original \citeX through \mciteCiteA using \@mciteCurRefName in aux and track
  1005. % \citeX -> \mciteCiteA{\@auxoutX}{multibibX}{\relax}
  1006. % {\let\@citex\mb@@citex\let\@newciteauxhandle\@auxoutX}
  1007. % {\mciteOrgcite}
  1008. % basic command name list
  1009. \def\@mciteMULTIBIBCiteCmdList{cite}
  1010. % add natbib names if natbib is loaded
  1011. \expandafter\ifx\csname ver@natbib.sty\endcsname\relax\else
  1012. \edef\@mciteMULTIBIBCiteCmdList{\@mciteMULTIBIBCiteCmdList,\@mciteNatbibCiteCmdList}\relax
  1013. \fi
  1014. \@for\@mcitecurcmdname:=\@mciteMULTIBIBCiteCmdList\do{\relax
  1015. \@mcitetmptoksA=\expandafter{\expandafter{\@mcitetempauxout}}\relax
  1016. \expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\@mcitetemptrackID}{\relax}}\relax
  1017. % install multibib \citeX internals into handler
  1018. \edef\@mcitetemp{{\let\noexpand\@citex\noexpand\mb@@citex
  1019. \let\noexpand\@newciteauxhandle\csname @auxout\@mciteCurRefName\endcsname}}\relax
  1020. \expandafter\@mciteAppendToTmpToksA\expandafter{\@mcitetemp}\relax
  1021. % forward to standard \cite (\mciteOrgcite), can't go through current \cite
  1022. % as that goes through mcite again and would write entries to standard aux
  1023. \expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\csname mciteOrg\@mcitecurcmdname\endcsname}}\relax
  1024. % define new \citeX wrapper
  1025. \expandafter\expandafter\expandafter\def\expandafter\expandafter\csname \@mcitecurcmdname\@mciteCurRefName\endcsname
  1026. \expandafter{\expandafter\mciteCiteA\the\@mcitetmptoksA}\relax
  1027. }% \do for \@mciteMULTIBIBCiteCmdList
  1028. %
  1029. % reroute original \nociteX through \mciteCiteA using \@mciteCurRefName in aux and track
  1030. % \nociteX -> \mciteCiteA{\@auxoutX}{multibibX}{\relax}
  1031. % {\relax}
  1032. % {\@mciteMULTIBIBgroupedOrgNocite}
  1033. \@mcitetmptoksA=\expandafter{\expandafter{\@mcitetempauxout}}\relax
  1034. \expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\@mcitetemptrackID}{\relax}{\relax}}\relax
  1035. % forward to standard \@mciteMULTIBIBgroupedOrgNocite, can't go through current \nocite
  1036. % as that goes through mcite again and would write entries to standard aux also because
  1037. % multibib changes \@auxout, we need to use the internally grouped version with
  1038. % the \@aux handler in it
  1039. \edef\@mcitetemp{{\noexpand\@mciteMULTIBIBgroupedOrgNocite{\@mciteCurRefName}}}
  1040. % define new \nociteX wrapper
  1041. \expandafter\@mciteAppendToTmpToksA\expandafter{\@mcitetemp}
  1042. \expandafter\expandafter\expandafter\def\expandafter\expandafter\csname nocite\@mciteCurRefName\endcsname
  1043. \expandafter{\expandafter\mciteCiteA\the\@mcitetmptoksA}\relax
  1044. % now reroute \bibliographyX
  1045. % save as \@mciteOrgMULTIBIBbibliographyX
  1046. \expandafter\let\expandafter\@mcitetemp\csname bibliography\@mciteCurRefName\endcsname
  1047. \expandafter\let\csname @mciteOrgMULTIBIBbibliography\@mciteCurRefName\endcsname\@mcitetemp
  1048. \@mcitetmptoksA=\expandafter{\csname @mciteOrgMULTIBIBbibliography\@mciteCurRefName\endcsname}\relax
  1049. \expandafter\edef\csname bibliography\@mciteCurRefName\endcsname{\def\@mciteoneshotBIBdecl{\def\noexpand\@mcitecurtrackID{\@mcitetemptrackID}}\the\@mcitetmptoksA}\relax
  1050. % we depend on the default \mciteauxout and \mcitetrackID for \cite, \nocite and \mcite
  1051. }% end ref name do loop
  1052. }% end def \@mcitePKGnewcites
  1053. %
  1054. % setup multibib BIB hooks
  1055. % no need to install bibliography wrapper uaing \@auxoutX as multibbl wrapper alters
  1056. % \@auxout to point to \@auxoutX before starting \mcitethebibliography
  1057. % Thus, the default bibteckID will work.
  1058. %
  1059. % warn if a mismatch between the settings of mciteplus entry label counter resets and those of multibib
  1060. \expandafter\@mcitetmptoksA\expandafter=\expandafter{\@mcitepkgBIBdecl}
  1061. \addto@hook\@mcitetmptoksA{\@mciteMULTIBIBcontinuouslabelsWarn}
  1062. \edef\@mcitepkgBIBdecl{\the\@mcitetmptoksA}
  1063. % reroute all \newcites calls through \@mciteMULTIBIBnewcites
  1064. \let\newcites\@mciteMULTIBIBnewcites
  1065. \fi% if multibib detected
  1066. % *** multibbl hooks
  1067. \expandafter\ifx\csname ver@multibbl.sty\endcsname\relax\else
  1068. \typeout{** mciteplus: Detected multibbl.sty. Invoking hooks.}\relax
  1069. % for checking that the user has called \newbibliography before \cite.
  1070. \def\@mciteMULTIBBLcheckAuxDefined{\expandafter\ifx\csname\mciteCiteSecIDArg @auxfile\endcsname\relax
  1071. \PackageError{mciteplus}{multibbl: Bibliography `\mciteCiteSecIDArg' has not been defined}{Use multibbl's \string\newbibliography\space to
  1072. declare this bibliography before using it in \string\cite.}\relax
  1073. \fi}
  1074. %\cite -> \mciteCiteB{\secID@auxfile}{multibbl\secID}{create aux track arguments}{\relax}{\mciteOrgcite}}
  1075. %\cite -> \mciteCiteB{\secID@auxfile}{multibbl\secID}{create aux track arguments}{\relax}{\mciteOrgcite}}
  1076. % we use prehandler to set aux and track arguments to use mciteCiteSecIDArg
  1077. \def\@mciteCiteWrapper{\mciteCiteB{Bogus auxout}{Bogus trackID}{\relax
  1078. \def\mciteCiteAuxArg{\csname \mciteCiteSecIDArg @auxfile\endcsname}\relax
  1079. \def\mciteCiteTrackArg{multibbl\mciteCiteSecIDArg}\@mciteMULTIBBLcheckAuxDefined}{\relax}{\mciteOrgcite}}
  1080. % nocite
  1081. \def\@mciteNociteWrapper{\mciteCiteB{Bogus auxout}{Bogus trackID}{\relax
  1082. \def\mciteCiteAuxArg{\csname \mciteCiteSecIDArg @auxfile\endcsname}\relax
  1083. \def\mciteCiteTrackArg{multibbl\mciteCiteSecIDArg}\@mciteMULTIBBLcheckAuxDefined}{\relax}{\mciteOrgnocite}}
  1084. % hook into bibliography at start of document, use one shot interface for single use setup of the aux and track ID
  1085. \AtBeginDocument{\let\mciteOrgbibliography\bibliography
  1086. % we need to update \mcitethebibliography's tracking ID, to reflect what multibbl is using,
  1087. % multibbl.sty does not read in non-main aux files. We use the one shot so that the definition is cleared
  1088. % after each bibliography (but in this case it would be anyway as it is defined inside the
  1089. % \bibliography environment).
  1090. \def\bibliography#1#2#3{\def\@mciteoneshotBIBdecl{\relax
  1091. \def\@mcitecurtrackID{multibbl#1}}
  1092. \mciteOrgbibliography{#1}{#2}{#3}}}
  1093. \fi% if multibbl detected
  1094. % *** bibunits hooks
  1095. \expandafter\ifx\csname ver@bibunits.sty\endcsname\relax\else
  1096. \typeout{** mciteplus: Detected bibunits.sty. Invoking hooks.}\relax
  1097. \def\@mciteBIBUNITSbibunit{\def\mcitetrackID{bibunits\@bibunitname}\relax
  1098. \def\mcitebibtrackID{bibunits\@bibunitname}\mciteOrgBIBUNITSbibunit}
  1099. \def\@mciteBIBUNITSbu@cite{\@startbibunitorrelax\mciteCiteA{\@bibunitaux}{\mcitetrackID}{\relax}{\@mciteBIBUNITSExtraDoListHandler}{\mciteOrgBIBUNITSbu@cite}}
  1100. \def\@mciteBIBUNITSbu@nocite{\@startbibunitorrelax\mciteCiteA{\@bibunitaux}{\mcitetrackID}{\relax}{\@mciteBIBUNITSExtraDoListHandler}{\mciteOrgBIBUNITSbu@nocite}}
  1101. \AtBeginDocument{\let\mciteOrgBIBUNITSbu@cite\bu@cite
  1102. \let\mciteOrgBIBUNITSbu@nocite\bu@nocite
  1103. \let\mciteOrgBIBUNITSbibunit\bibunit
  1104. \let\mciteOrgBIBUNITSstd@bibliography\std@bibliography
  1105. \let\bibunit\@mciteBIBUNITSbibunit
  1106. \let\bu@cite\@mciteBIBUNITSbu@cite
  1107. \let\bu@nocite\@mciteBIBUNITSbu@nocite
  1108. % have to restore main track ID for global bibliography when using \bibliographyunit
  1109. \def\std@bibliography{\def\mcitebibtrackID{main}\mciteOrgBIBUNITSstd@bibliography}}
  1110. \fi% if bibunits detected
  1111. % *** backref.sty (from hyperref) hooks
  1112. \expandafter\ifx\csname ver@backref.sty\endcsname\relax\else
  1113. \typeout{** mciteplus: Detected backref.sty. Invoking hooks.}\relax
  1114. % disable backref's \bibitem intercept within mcitethebibliography
  1115. \expandafter\@mcitetmptoksA\expandafter=\expandafter{\mcitethebibliographyHook}
  1116. \addto@hook\@mcitetmptoksA{\def\BR@@lbibitem{\@lbibitem}\def\BR@@bibitem{\@bibitem}}
  1117. \edef\mcitethebibliographyHook{\the\@mcitetmptoksA}
  1118. %\def\BR@bibitem{\BRorg@bibitem}
  1119. % and install our own
  1120. \def\mciteBACKREFform{{}\ \BR@backref{\@mcitecurhead}}
  1121. \expandafter\@mcitetmptoksA\expandafter=\expandafter{\mciteEndOfBibGroupPresubcloseHook}
  1122. \addto@hook\@mcitetmptoksA{\mciteBACKREFform}
  1123. \edef\mciteEndOfBibGroupPresubcloseHook{\the\@mcitetmptoksA}
  1124. \fi % if backref.sty detected
  1125. % *** citeref.sty hooks
  1126. \expandafter\ifx\csname ver@citeref.sty\endcsname\relax\else
  1127. \typeout{** mciteplus: Detected citeref.sty. Invoking hooks.}\relax
  1128. % disable citeref's \bibitem intercepts within mcitethebibliography
  1129. \expandafter\@mcitetmptoksA\expandafter=\expandafter{\mcitethebibliographyHook}
  1130. \addto@hook\@mcitetmptoksA{\def\@@lbibitem{\@lbibitem}\def\@@bibitem{\@bibitem}}
  1131. \edef\mcitethebibliographyHook{\the\@mcitetmptoksA}
  1132. %\def\@@lbibitem{\@lbibitem}
  1133. %\def\@@bibitem{\@bibitem}
  1134. % and install our own
  1135. \def\mciteCITEREFform{\bibitempages{\@citerefpages{\@mcitecurhead}}}
  1136. \expandafter\@mcitetmptoksA\expandafter=\expandafter{\mciteEndOfBibGroupPresubcloseHook}
  1137. \addto@hook\@mcitetmptoksA{\mciteCITEREFform}
  1138. \edef\mciteEndOfBibGroupPresubcloseHook{\the\@mcitetmptoksA}
  1139. \fi % if citeref.sty detected
  1140. % *** detect attempts to use incompatible packages ***
  1141. % might be best not to lockout amsrefs and biblatex - maybe somebody wants
  1142. % and knows how to use them "in parallel" with mciteplus
  1143. % *** incompatible with bibtopic.sty
  1144. \expandafter\ifx\csname ver@bibtopic.sty\endcsname\relax\else
  1145. \PackageError{mciteplus}{Bibtopic.sty cannot be used with mciteplus.sty}{These two packages won't work together.}\relax
  1146. \fi
  1147. % *** incompatible with inlinebib.sty
  1148. \expandafter\ifx\csname ver@inlinebib.sty\endcsname\relax\else
  1149. \PackageError{mciteplus}{inlinebib.sty cannot be used with mciteplus.sty}{These two packages won't work together.}\relax
  1150. \fi
  1151. % *** incompatible with jurabib.sty
  1152. \expandafter\ifx\csname ver@jurabib.sty\endcsname\relax\else
  1153. \PackageError{mciteplus}{jurabib.sty cannot be used with mciteplus.sty}{These two packages won't work together.}\relax
  1154. \fi
  1155. % *** incompatible with opcit.sty
  1156. \expandafter\ifx\csname ver@opcit.sty\endcsname\relax\else
  1157. \PackageError{mciteplus}{opcit.sty cannot be used with mciteplus.sty}{These two packages won't work together.}\relax
  1158. \fi
  1159. % *** incompatible with splitbib.sty
  1160. \expandafter\ifx\csname ver@splitbib.sty\endcsname\relax\else
  1161. \PackageError{mciteplus}{Splitbib.sty cannot be used with mciteplus.sty}{These two packages won't work together.}\relax
  1162. \fi
  1163. \fi % if hooks enabled
  1164. \endinput