6

The standard \cite{some_ref} command produce citation text like [1], but i'm looking for citation like [1*]. How can i define new cite command for such behavior?

TheBug
  • 5,649
  • Welcome to tex.sx! There are many possible citation/bibliography formats -- please provide some background to your question. Should a star be added to every label number? Should a star inidicate some kind of "special" source? – lockstep May 05 '11 at 17:12
  • Sorry for confusing question. I need indicate special source. So i think it's better to define new command like \cites{some_ref} in this case, instead of redefining existing command. I'll update question to remove confusion. – TheBug May 05 '11 at 17:18

3 Answers3

3

Since you are using natbib, there's no need to define any new commands; you can achieve the desired effect using the \citetext and \citealp commands:

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Steve Somebody},
title= {The Title},
year={2011},
publisher={The publisher}
}
\end{filecontents}
\documentclass{article}
\usepackage[numbers]{natbib}

\begin{document}

\citetext{\citealp{test}*}

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}
Gonzalo Medina
  • 505,128
2
\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Steve Somebody},
titel= {The Title},
year={2011},
}
\end{filecontents}
\documentclass{article}
\makeatletter
\DeclareRobustCommand\mycite{%
  \@ifnextchar [{\@tempswatrue\@mycitex}{\@tempswafalse\@mycitex[]}}
\def\@mycitex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@mycite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}} 
\def\@mycite#1#2{[{#1*\if@tempswa , #2\fi}]}%
\makeatother
\begin{document}
\cite{test}\qquad \mycite{test} \qquad \mycite[p.~1]{test}
\bibliography{\jobname}
\bibliographystyle{plain}
\end{document}
Marco Daniel
  • 95,681
  • then all \cite get the star –  May 05 '11 at 17:42
  • @Herbert: I edited my post ;-) – Marco Daniel May 05 '11 at 17:50
  • Why don't you just redefine \@cite to \@mycite rather than copying over the entire contents of \@citex? I can't even tell what you changed other than the star in \@mycite. – Ryan Reich May 05 '11 at 18:03
  • @Ryan: if I redefine \@cite , every cite-command get the star. – Marco Daniel May 05 '11 at 18:15
  • @Marco: Your sample works as i expected. But when i tried it with my real document, i got error ! Use of \@ doesn't match its definition. \mycite ->\@i fnextchar [{\@tempswatrue\@mycitex}{\@tempswafalse\@mycitex[]}

    Seems, problem with natbib package. How your sample can be fixed in this case?

    – TheBug May 05 '11 at 18:19
  • @TheBug: you have to use \makeatletter--\makeatother. See also the example of Herbert. – Marco Daniel May 05 '11 at 18:28
  • @Marco: Thanks, it works with \makeatletter--\makeatother – TheBug May 05 '11 at 18:48
  • @Marco: You could do something like \def\mycite{{\let\@cite=\@mycite\cite}}. Unless \cite doesn't \globalize the things it changes externally, this won't break anything. – Ryan Reich May 05 '11 at 18:57
2

with a second switch it is a bit shorter. Use \cite or cite*

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Steve Somebody},
titel= {The Title},
year={2011},
}
\end{filecontents}
\documentclass{article}
\makeatletter
\newif\if@tempswb
\DeclareRobustCommand\cite{%
  \@ifnextchar*{\@tempswbtrue\cite@i}{\@tempswbfalse\cite@i*}}
\def\cite@i*{\@ifnextchar[{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}}
\def\@cite#1#2{[{#1\if@tempswb*\fi\if@tempswa , #2\fi}]}%
\makeatother
\begin{document}

\cite{test}\qquad \cite*{test} \qquad \cite*[p.~1]{test}

\bibliography{\jobname}
\bibliographystyle{plain}
\end{document}
  • Your sample works fine. But with my document it leads to error `Runaway argument? ]{test1} \cite *{test2} ! Paragraph ended before @citex was complete. \par` Can you help with this issue? – TheBug May 05 '11 at 18:46
  • @TheBug: natbib redefines all macros itself and it would have been a good idea if you had this mentioned before ... –  May 05 '11 at 18:50