# Reference in the same style for section and appendix

I have a small macro when referencing a section/appendix:

\newcommand{\secref}[1]{Sec.~\ref{#1}}


Now, when referencing a section, it works just fine and puts something like Sec. 2.5. When referencing an appendix, however, it puts Sec. Appendix A.

How does LaTeX decide whether it puts just the number (in the case of sections), or whether it puts Appendix and the "number" A? How can I influence this? How can I achieve a reference macro that automatically puts Sec./App./Chap. as appropriate?

• We would need to see a code to tell. That being said, why don't you simply load cleveref which adds the type of reference, and is customisable? – Bernard Jun 6 '18 at 20:28
• @Bernard: cleveref seems to be a good solution in general, but there still remains the question how \ref decides what it prints. – Michael Jun 6 '18 at 20:34
• This can be coded in a clever.cfg file. This being said, the case of appendix is probably trickier and probably require using the appendix and apptools packages. – Bernard Jun 6 '18 at 21:24