Command already defined
Renaming using \let
Name clashes can be resolved by renaming. In this case these are simple environments. An environment name
defines two macros \name
and \endname
(the latter can also left undefined, because it is called via \csname
).
\documentclass{exam}
\newcommand*{\renameenviron}[1]{%
\expandafter\let\csname exam-#1\expandafter\endcsname
\csname #1\endcsname
\expandafter\let\csname endexam-#1\expandafter\endcsname
\csname end#1\endcsname
\expandafter\let\csname #1\endcsname\relax
\expandafter\let\csname end#1\endcsname\relax
}
\renameenviron{framed}
\renameenviron{shaded}
\renameenviron{leftbar}
\usepackage{framed}
\begin{document}
\end{document}
However this method overwrites the internal stuff of framed
in exam
by the original code of package framed
, see below for further discussion.
Simulate package loading
The class exam
says:
% Donald Arseneau <...>, who created the excellent % ``framed.sty'' and generously allowed me to include basically the % whole thing in exam.cls, making the few changes needed for it to % work well with question environments: % framed.sty v 0.8a 21-Jul-2003 % Copyright (C) 1992-2003 by Donald Arseneau % These macros may be freely transmitted, reproduced, or modified % provided that this notice is left intact.
That could mean, framed
is already loaded. It might not make sense to load it twice.
Then LaTeX can be tricked to think that the package is already loaded:
\documentclass{exam}
\makeatletter
\expandafter\providecommand\expandafter*\csname [email protected]\endcsname
{2003/07/21 v0.8a Simulated by exam}
\makeatother
\usepackage{framed}
\begin{document}
\end{document}
The long story
Both methods above do not address the question, what has changed in the implementation of framed
in class exam
to the original framed
. The environments are one side, the internal stuff the other side. For example, internal macros are defined using \def
that does not generate an error, if the macro is already defined. In the first method, the later loaded package framed
overwrites the internal stuff of class exam
. In the second method the version of framed
in class exam
is used.
Advantage of the first method: The latest framed
is used including bug fixes and new features (if there are any). On the downside, the changes of exam
are lost
(A quick look reveals some margin and positioning stuff). Therefore the second method might be better here.
If you are lucky, the second method already works for your document.
Otherwise it can be that this knitr
requires a later version of framed
or expects an unmodified framed
. These cases cause lots of work, because the different macro versions need to be analyzed for differences and merging or providing different environments.