4

I'm using the multibib package to differentiate between different types of references. Additionally to \cite{} I've defined the command \citemine{}.

Citing works perfectly fine, but sometimes I'd like to have references of both types inside one bracket. That is, rather than \cite{RefA}\citemine{RefB} resulting in [1][2] I'd like to have [1,2].

Update April 28th: I have come to a (nasty) solution that is just missing some minor detail. My updated MWE does result in [ 1, 2], but of course I like to have [1, 2]. I'm quite confused, because I have no idea where this additional space might come from. Any help is appreciated!

\documentclass[]{scrbook}

% bibstlye

\usepackage{cite}
\usepackage{multibib}

\newcites{mine}{my stuff}

\newcommand{\citeBoth}[2]{
    \renewcommand{\citeleft}{}
    \renewcommand{\citeright}{}
    [#1,#2]
    \renewcommand{\citeleft}{[}
    \renewcommand{\citeright}{]}
    }


\begin{document}

Two cite examples:

\cite{foo}
\cite{foo2}
\citemine{bar}

\citeBoth{\cite{foo, foo2}}{\citemine{bar}}

\bibliographystylemine{plain}
\bibliographymine{bibfile}

\bibliographystyle{plain} 
\bibliography{bibfile}

\end{document}

and corresponding bibfile:

@Article{foo,
  author={foo},
  title={foo},
  journal={foo},
  year={200},
  volume={60},
  number={23},
  pages={6641--8},
}

@Article{bar,
    author={foo},
    title={foo},
    journal={foo},
    year={200},
    volume={60},
    number={23},
    pages={6641--8},
}

@Article{foo2,
    author={foo2},
    title={foo2},
    journal={foo2},
    year={200},
    volume={60},
    number={23},
    pages={6641--8},
}
Mandy
  • 199
  • 1
    Could you please give us a MWE? If your citations can be sorted out automatically (different bibtype or keywords, etc.) it would be a lot easier to create the proper macros. If not, then the solution is more complex. – ienissei Apr 24 '15 at 08:53
  • 2
    \renewcommand{\citeleft}{\unskip} inside of \citeBoth. – Steven B. Segletes Apr 28 '15 at 16:52
  • Thank's that did the trick. Do you like to post this an answer? There are 50 bounty points to earn ;) – Mandy Apr 29 '15 at 05:40
  • For all who like to use this solution: if you want to integrate your citations in a text the definition should be written in one line as \newcommand{\citeBoth}[2]{\renewcommand{\citeleft}{}\renewcommand{\citeright}{}\renewcommand{\citeleft}{\unskip}[#1,#2]\renewcommand{\citeleft}{[}\renewcommand{\citeright}{]}}. Otherwise you will get nasty spaces within the text. – Mandy Apr 29 '15 at 06:59

1 Answers1

2

Turning my comment into an answer...

The extraneous space is caused because the implementation of \cite issues a space before the left bracket of the citation, so that a cite appears as my citation [1]. Since the OP uses \cite as an argument inside of \citeBoth, a means is needed to eliminate that issued space, which now occurs inside the brackets of \citeBoth.

The way to accomplish this is to redefine \citeleft not merely as a empty macro {}, but to redefine it to unskip the previously issued space. Thus, employing \renewcommand{\citeleft}{\unskip} in the definition of \citeBoth should solve the problem.

Note I also issued the cite inside of \citeBoth as [#1,\,#2], so as to insert a small space after the comma.

\newcommand{\citeBoth}[2]{
    \renewcommand{\citeleft}{\unskip}
    \renewcommand{\citeright}{}
    [#1,\,#2]
    \renewcommand{\citeleft}{[}
    \renewcommand{\citeright}{]}
    }

I don't know enough about multibib to know why \citemine isn't functioning properly (it didn't work before or after my fix); however, the spacing problem cited by the OP is resolved.

\documentclass[]{scrbook}
\usepackage{filecontents}
\begin{filecontents}{bibfile.bib}
@Article{foo,
  author={foo},
  title={foo},
  journal={foo},
  year={200},
  volume={60},
  number={23},
  pages={6641--8},
}

@Article{bar,
    author={foo},
    title={foo},
    journal={foo},
    year={200},
    volume={60},
    number={23},
    pages={6641--8},
}

@Article{foo2,
    author={foo2},
    title={foo2},
    journal={foo2},
    year={200},
    volume={60},
    number={23},
    pages={6641--8},
}
\end{filecontents}
% bibstlye

\usepackage{cite}
\usepackage{multibib}

\newcites{mine}{my stuff}

\newcommand{\citeBoth}[2]{
    \renewcommand{\citeleft}{\unskip}
    \renewcommand{\citeright}{}
    [#1,\,#2]
    \renewcommand{\citeleft}{[}
    \renewcommand{\citeright}{]}
    }


\begin{document}

Two cite examples:
\cite{foo}
\cite{foo2}
\citemine{bar}

\citeBoth{\cite{foo, foo2}}{\citemine{bar}}

\bibliographystylemine{plain}
\bibliographymine{bibfile}

\bibliographystyle{plain} 
\bibliography{bibfile}

\end{document}

enter image description here