Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to create 2 commands

\newcommand\deffeat[1]...
\newcommand\reffeat[1] ...

The deffeat command would print out as something like \textbf{F001},

and the reffeat command would reference the deffeat with the same feature name plus have the exact same text.

My current experiment is using the following:

\newcounter{thefeatures}
\setcounter{thefeatures}{1}

\newcommand{\deffeat}[1]{
    \phantomsection[a]
    %XXX: \tag{F~\{cifeatures}}
    \label{#1}
    \textbf{F~\arabic{thefeatures}}
    \addtocounter{thefeatures}{1}
}

It's still missing the spell the same text feature (currently I'm using \ref).

edit current state:

using cleveref

\newcounter{thefeatures}
\setcounter{thefeatures}{0}

\crefname{thefeatures}{feature}{features}

\newcommand{\deffeat}[1]{
    \phantomsection
    \refstepcounter{thefeatures}
    \label{#1}
    \textbf{F\arabic{thefeatures}}
}

\crefformat{thefeatures}{#2F#1#3}
share|improve this question
1  
Welcome to TeX.SX! –  krlmlr Nov 1 '12 at 10:15

1 Answer 1

up vote 6 down vote accepted

By default, \ref prints only the number of the reference. Take a look at the cleveref package to print the name, too. Some minor customization is required for the new reference type, check \crefname in the cleveref manual.

Note that your example had several minor deficiencies, and also is incomplete. A full MWE would have been better. Anyway, the following pattern should help achieving what you are looking for:

\documentclass{scrartcl}
\pagestyle{empty}

\usepackage{hyperref}
\usepackage{cleveref}

\newcounter{thefeatures}
\setcounter{thefeatures}{0}

\crefname{thefeatures}{feature}{features}

\newcommand{\deffeat}[1]{
    \phantomsection
    \refstepcounter{thefeatures}
    \label{#1}
    \textbf{F~\arabic{thefeatures}}
}

\begin{document}
    \deffeat{MyFeature}

    \deffeat{MyFeature2}

    \Cref{MyFeature,MyFeature2}
\end{document}

Result of compilation

As you can see, the package tries hard to be clever.

See this related question: How to get more complete references.

share|improve this answer
    
i dont see how i could use the same text for the definition site and the reference site tho (ideally formated as F followed by 3 digits) –  Ronny Nov 1 '12 at 14:10
1  
@Ronny: See Section 7.2 of the cleveref manual on full control of reference formatting. Something along the lines of \crefformat{thefeatures}{#2F\prependzeros[3]{#1}#3} should do the trick, but \prependzeros[3]{#1} is a macro still to be implemented, perhaps using the stringstrings package. –  krlmlr Nov 1 '12 at 14:14
    
i implemented the part without prependzeroes to see if it works however i get a undefined reference when doing \Cref{test} after a \deffeat{test} –  Ronny Nov 1 '12 at 14:43
    
@Ronny: Does \cref{test} work? Have you used \Crefformat? –  krlmlr Nov 1 '12 at 14:51
1  
Right: tex.stackexchange.com/questions/1863/… –  krlmlr Nov 2 '12 at 8:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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