Cleveref in Lyx

It is really tricky to make a nice-looking cross reference in lyx. I managed to do it. So I share it here for me in the future.

\usepackage{xcolor}
\usepackage{nameref}

\definecolor{ForestGreen}{rgb}{0.1333,0.5451,0.1333}
\definecolor{DarkRed}{rgb}{0.8,0,0}
\definecolor{Red}{rgb}{1,0,0}

\usepackage[linktocpage=true,
pagebackref=true,colorlinks,
linkcolor=DarkRed,citecolor=ForestGreen,
bookmarks,bookmarksopen,bookmarksnumbered]
{hyperref}

\usepackage{cleveref}

\crefalias{thm}{theorem}

\let\oldlem\lem
\renewcommand{\lem}{%
\crefalias{thm}{lemma}
\oldlem
}

\let\olddefn\defn
\renewcommand{\defn}{%
\crefalias{thm}{definition}
\olddefn
}

\renewcommand\equationautorefname{\@gobble}

\AtBeginDocument{%
\let\ref\Cref
}

2 thoughts on “Cleveref in Lyx

    • No. This literally overrides \ref with \cref.
      For example, when we compile with “\ref{lem: blah}” inside Lyx, we see “Lemma 4” instead of just “4”.

Leave a comment