Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
  \let\savenewcommand\newcommand
  \let\newcommand\renewcommand
  \tenpointdecl
  \let\newcommand\savenewcommand
  \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?

share|improve this question
    
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. –  Zack Nov 13 '11 at 20:33
    
One might think to do a "search and replace" of \newcommand with \renewcommand, but this is not possible; etoolbox's \patchcmd can do only a one shot search and replace at a time and one should know how many \newcommand are to be changed. It might be used to cut off the \endinput, but it's like using a gun to kill a fly. –  egreg Nov 13 '11 at 20:39
add comment

2 Answers

up vote 6 down vote accepted

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

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

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

\newenvironment{fontsizeten}
  {\par                           % go in vertical mode
   \let\endinput\relax            % neutralize \endinput
   \let\newcommand\renewcommand   % the commands are already defined
   \clo@sizeten                   % "read" the file
   \let\endinput\clo@endinput     % revert to the original command
   \let\newcommand\clo@newcommand % 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.

share|improve this answer
    
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. –  Zack 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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.