# Correct capitalization for crossreferences

There are packages that allow us to nicely reference sections/figures/etc. without having to actually specify to what we're referring, such as hyperref's \autoref or cleverref's \cref. That's particularly nice in case of sections because it avoids mistakes when we change the hierarchy of a document.

My question is why no package correctly identifies whether the name should start with a capital or not. For example the following should use a lowercase letter for the first reference but a capital for the later:

\documentclass{article}

\begin{document}
\section{Foo}
\label{foo}
Correctly lowercased reference \magicref{foo}. % section 1.
\end{document}


Hyperref just always uses lowercase while cleverref allows the author to specify the correct case. But what is the problem with not using some heuristics to correctly identify which case should be used?

It seems like a very useful thing to have, so I guess there must be some technical problems that make this harder than it looks. Or maybe it exists and I just haven't found it yet?

-
e.g.\ \magicref{foo}. I believe the author should resolve ambiguity whenever possible, and it would probably be impossible to code for all permutations for non-sentence-ending periods which are followed by an invocation of \magicref{foo}. Personally, I use cleveref with the capitalise option, so all labels have the first letter capitalised, regardless of their position in a sentence. – sudosensei Jun 17 '14 at 0:39
@sudosensei I'm sure there are some edge cases that would be hard to catch (can't think of any, but typography is complex enough that I'm sure they exist), but e.g.\ , etc. wouldn't be a problem - we use the \  after all explicitly to tell LaTeX that the preceding dot doesn't end a sentence. "Perfect is the enemy of good" fits I think. Not sure what I think about capitalizing sections everywhere.. well maybe I should just write all my papers in German - that would take care of this ;) – Voo Jun 17 '14 at 0:52

For one, just like there are outliers to the as it is now, there are possibly also outliers to the use when it is automated. Also, this would depend on the implementation of the referencing scheme. For example, the following* works with hyperref's \autoref:

\documentclass{article}
\usepackage{hyperref}
\renewcommand{\sectionautorefname}{\ifnum\spacefactor>1000 Section\else section\fi}
\begin{document}
\section{Foo}
\label{foo}
Correctly lowercased reference \autoref{foo}. % section 1.
\end{document}


In the above, we check whether \spacefactor is greater than 1000 - typically associated with an end-of-sentence punctuation, as indicated in TeX by Topic (section 20.5. More on the space factor, p 188):

In the plain format two macros are defined that switch between uniform interword spacing and extra space after punctuation. The macro \frenchspacing sets the space factor code of all punctuation to 1000; the macro \nonfrenchspacing sets it to values greater than 1000.

Here are the actual definitions from plain.tex:

\def\frenchspacing{\sfcode‘\.\@m \sfcode‘\?\@m
\sfcode‘\!\@m \sfcode‘\:\@m
\sfcode‘\;\@m \sfcode‘\,\@m}
\def\nonfrenchspacing{\sfcode‘\.3000 \sfcode‘\?3000
\sfcode‘\!3000 \sfcode‘\:2000
\sfcode‘\;1500 \sfcode‘\,1250 }


where

\mathchardef\@m=1000


is given in the plain format.

This, however, doesn't work in the same straight-forward way when using cleveref (for example). As mentioned, this may be due to the implementation.

Perhaps the generic reason is: what if one defines some different value for \spacefactor in your document? There would be no way a reference package author would know that. And, even if they do, it has to be incorporated in some way, also allowing the user to override this automated adjustment since everyone is different, and requires different use-cases. It may just seem too much to consider when the manual override already exists in the form of something like \cref and \Cref.

In support against such automation, I usually take the following approach. You write a sentence that starts with a reference, so you use the capitalized version of the reference. If this suddenly changes because of an insertion close to this point in your document, change it to the other format while you're editing... it's really as simple as that.

* See Automatically capitalize macro output if used after a period.

-