Generalhow to use pass in environment parameter to \scalebox?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
latexian
Posts: 19
Joined: Wed Aug 05, 2009 7:57 am

how to use pass in environment parameter to \scalebox?

Post by latexian »

Here is my trivial example that could not be compiled.
The idea is to pass in the environment parameter to \scalebox.

Code: Select all

\documentclass{minimal}
\usepackage{graphicx}

\newsavebox{\tempbox}
\newenvironment{myscalebox}[1]
{\begin{lrbox}{\tempbox}}
{\end{lrbox}\scalebox{#1}{\usebox{\tempbox}}}

\begin{document}
\begin{myscalebox}{10}
hello world
\end{myscalebox}
\end{document}
Let me know which part of the code did not follow the rule.


Thank you in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

how to use pass in environment parameter to \scalebox?

Post by phi »

You cannot use environment arguments in the end code. Save the argument in a variable:

Code: Select all

\newenvironment{myscalebox}[1]{%
  \newcommand*{\scalingfactor}{#1}%
  \begin{lrbox}{\tempbox}%
}{%
  \end{lrbox}%
  \scalebox{\scalingfactor}{\usebox{\tempbox}}%
}
latexian
Posts: 19
Joined: Wed Aug 05, 2009 7:57 am

Re: how to use pass in environment parameter to \scalebox?

Post by latexian »

@phi,

Thank you for your response.

It works the way I want.


regards,

LaTeXian
Post Reply