2

I want two things: 1. to be able to use \cref across different files and 2. to display certain environments (just the theorems for example) from an external file.

What I mean by (2) is the following. Suppose I have theorems in a file called external.tex. Suppose I'm working in main.tex. I want all of the theorems from external.tex to be pasted into main.tex without having to rewrite them.

Here is my code for (1):

external.tex:

\documentclass{article}
\usepackage{amsmath,cleveref}
\newtheorem{lem}{Lemma}
\begin{document}
\begin{lem}\label{mylemma}
blah blah blah
\end{lem}
\end{document}

main.tex:

\documentclass{article}
\usepackage{cleveref}
\usepackage{xr}
\externaldocument[ext:]{external}
\begin{document}
using \cref{ext:mylemma}
\end{document}

When I use \ref{ext:mylemma}, it works. It just displays the number 1. When I use \cref{ext:mylemma}, I get "?? 1". How do I fix this?

  • 1
    Welcome! I think your two questions are independent of each other and should be asked as two separate questions. Since you already have an answer to the first part of your question, I would suggest editing this question to remove the second part and ask the removed part as a new separate question again. – cryingshadow Dec 20 '15 at 0:31
2

cleveref in main.tex does not know what the label type lem is (as indicated by the warning: cref reference format for label type `lem' undefined). Therefore, add \newtheorem{lem}{Lemma} to the preamble of main.tex to define it therein.

\documentclass{article}
\usepackage{cleveref}
\newtheorem{lem}{Lemma}
\usepackage{xr}
\externaldocument[ext:]{external}
\begin{document}
using \cref{ext:mylemma}
\end{document}
| improve this answer | |
  • cleveref is one of the packages that should be loaded right at the end of the preamble – user31729 Dec 20 '15 at 8:54
2

Instead of repeating the definition of newtheorem lemma it's possible to make cleveref aware of lem using \crefname or \Crefname

\documentclass{article}

\usepackage{xr}
\usepackage{cleveref}
\externaldocument[ext:]{external}
\crefname{lem}{lemma}{lemmata}
\Crefname{lem}{Lemma}{Lemmata}

\begin{document}
using \cref{ext:mylemma} or \Cref{ext:mylemma}
\end{document}
| improve this answer | |

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.