1

Unfortunately, my BibTeX file has been processed by a program that changed all the keys to lowercase. Now my TeX has a mixture of uppercase and lowercase keys. If I cite something once with \citep{CASE} and later with \citep{case}, BibTeX throws the error: BibTeX Case mismatch error between cite keys CASE and case.

Can I redefine citep, citet, and citealt to first cast everything to lowercase before calling it, so that either uppercase or lowercase will work?

  • 4
    While it is probably possible it would be imho better to correct the document. – Ulrike Fischer Feb 7 '18 at 11:03
2

Can I redefine \citep, \citet, and \citealt to first cast everything to lowercase ... ?

If this has to be done, it's probably best to take a pre-processor approach. Why? natbib's citation macros (\citet, \citep, \citealt, etc.) can take either one or two optional arguments. Modifying the behavior of such macros could be error-prone.

In a pre-processor approach, the arguments of all \cite-type macros would be converted to all-lowercase letters on the fly, before TeX starts its usual work. This approach is feasible if one uses LuaLaTeX and sets up a suitable Lua function that's assigned to the process_input_buffer callback. (This callback operates at a very early stage, i.e., as a pre-processor.) The following example code implements this idea.

enter image description here

% !TEX TS-program = lualatex

%% Create a bib file with two sample entries
\RequirePackage{filecontents}
\begin{filecontents*}{mybib.bib}
@misc{aa:3001,
  author = "Anne Author",
  title  = "Thoughts",
  year   = 3001,
}
@misc{aazz:3002,
  author = "Anne Author and Zelda Zwicky",
  title  = "Further Thoughts",
  year   = 3002,
}
\end{filecontents*}

\documentclass{article}

\usepackage{luacode} % for 'luacode' environment
\begin{luacode}
-- The function 'lowercase_cite' does the heavy lifting:
function lowercase_cite ( s )
   return ( s:gsub ( "(\\[cC]ite.-)(%b{})" , 
            function (a,b)  return (a..string.lower(b)) end ) )
end
\end{luacode}

%% Assign 'lowercase_cite' to LuaTeX's 'process_input_buffer' callback
\AtBeginDocument{\directlua{luatexbase.add_to_callback (
   "process_input_buffer" , lowercase_cite , "lowercase_cite" )}}

%% Load 'natbib' package and select a suitable bibliography style
\usepackage[round,authoryear]{natbib}
\bibliographystyle{plainnat}

\begin{document}
\citet {aa:3001}; \citep{aazz:3002}

\cite {Aa:3001}; \citep {aAZz:3002}

\citealt {AA:3001}; \citealp{AazZ:3002}

\bibliography{mybib}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.