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?
-
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?– lockstepMay 5, 2011 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.– TheBugMay 5, 2011 at 17:18
3 Answers
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}
-
Thanks, defined new command as in your example
\def\mycite#1{\citetext{\citealp{#1}*}}
– TheBugMay 5, 2011 at 18:58 -
\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}
-
then all
\cite
get the star– user2478May 5, 2011 at 17:42 -
-
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
. May 5, 2011 at 18:03 -
-
@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?– TheBugMay 5, 2011 at 18:19
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. <to be read again> \par
Can you help with this issue?– TheBugMay 5, 2011 at 18:46 -
@TheBug:
natbib
redefines all macros itself and it would have been a good idea if you had this mentioned before ...– user2478May 5, 2011 at 18:50