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?

2
  • 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 5 '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 5 '11 at 17:18
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}
2
  • Thanks, defined new command as in your example \def\mycite#1{\citetext{\citealp{#1}*}}
    – TheBug
    May 5 '11 at 18:58
  • Can I do it without using the natbib?
    – Abu Shoeb
    Dec 29 '20 at 0:15
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}
8
  • then all \cite get the star
    – user2478
    May 5 '11 at 17:42
  • @Herbert: I edited my post ;-) May 5 '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 5 '11 at 18:03
  • @Ryan: if I redefine \@cite , every cite-command get the star. May 5 '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 5 '11 at 18:19
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}
2
  • 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?
    – TheBug
    May 5 '11 at 18:46
  • @TheBug: natbib redefines all macros itself and it would have been a good idea if you had this mentioned before ...
    – user2478
    May 5 '11 at 18:50

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.