# Environment that applies sizeN.clo

My document has a base font size of 12pt, but I want the figures to be typeset as if the base font size were 10pt (some of the figures use graphics packages that hardwire font size commands rather than offering \foosize indirections, so I can't just fix it that way).

I have found Switching to different font size(s) locally, so my goal is to wrap that up in a \newenvironment. EDIT: It is not quite as simple as using How do I create a macro which reads the content of a file when the macro is defined?, but I now have this:

\usepackage{catchfile}
\CatchFileDef{\tenpointdecl}{size10.clo}{\makeatletter}
\newenvironment{fontsizeten}{%
\let\saveendinput\endinput
\let\endinput\relax
\tenpointdecl
\let\endinput\saveendinput
}{}


This works, but strikes me as inelegant. It would be better if there were a way to rewrite the contents of \tenpointdecl so that the \lets every time it is invoked were unnecessary. Suggestions?

-
Those \let are necessary and take up a negligible amount of time. –  egreg Nov 13 '11 at 20:24
I'm not concerned with time, but with tidiness. –  zwol Nov 13 '11 at 20:33

One has to avoid reading \endinput, besides redefining \newcommand:

\documentclass[a4paper,12pt]{article}
\usepackage{catchfile,lipsum}

\makeatletter
\let\clo@endinput\endinput
\CatchFileDef{\clo@sizeten}{size10.clo}{}

\newenvironment{fontsizeten}
{\par                           % go in vertical mode
\let\endinput\relax            % neutralize \endinput
\let\endinput\clo@endinput     % revert to the original command
}
{\par}
\makeatother

\begin{document}
\lipsum[1-2]

\begin{fontsizeten}
\lipsum[1-2]
\end{fontsizeten}

\lipsum[1-2]
\end{document}


As usual, lipsum is used only to create dummy text. The original meaning of \newcommand and \endinput should be restored immediately after the redefinitions of size10.clo have been performed.

-
As you can see from my edit, I came up with nearly the same thing based on Martin Scharrer's suggestion. I don't understand why it's necessary to neutralize \ProvidesFile, it appears to be harmless? The "circular definition of \normalsize" isn't causing me any trouble either. –  zwol Nov 13 '11 at 20:25
@Zack That's quite strange. I don't know why, but the first approach stopped at \normalsize. I'll edit my answer. –  egreg Nov 13 '11 at 20:28

I would consider rereading the file every time. This wouldn't be that less efficient as long you don't switch quite a lot.

Anyway, you can assign the content of the file to a macro using the catchfile package. It requires e-TeX and avoids the issues you having. See also How do I create a macro which reads the content of a file when the macro is defined?.

The problems you see is for once that TeX's \input (\@@input in LaTeX) doesn't work in \edef (or the global \xdef), because AFAIK TeX considers its an error when it encounters the end of a file during a macro definition. Also you shouldn't use \edef or \xdef because this expands not only \@@input, but also its content. You don't want that! You would need to use \expandafter instead, but this doesn't work either because of the above reason.

-