# Change \textheight in function of width

Good day. I want define an environment that change the text height in function of the width

\documentclass[a4paper]{book}
\usepackage{lipsum}

\begin{document}
\the\textwidth---\the\textheight

\newenvironment{whtext}[1]{%
\newpage\begingroup
\hsize=#1
\vsize=\dimexpr\textheight*\numexpr\hsize/\textwidth\relax
\textwidth=\hsize
\textheight=\vsize}%
{\endgroup\newpage}

\lipsum[1-10]

\begin{whtext}{15cm}
\the\textwidth---\the\textheight
\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}

\end{document}


what i should do?

• Do about what? What is your question? – user31729 Feb 6 '15 at 20:14
• How i can do this it doesn't work like this – touhami Feb 6 '15 at 20:15
• how to define \vsize – touhami Feb 6 '15 at 20:16
• Somewhat related to tex.stackexchange.com/questions/48172/… – user31729 Feb 6 '15 at 20:33
• that doesn't help i need to change textheight in next page as geometry do but without it – touhami Feb 6 '15 at 20:49

It's not a good idea to manipulate textheight etc. directly. The geometry package provides the means for doing this with \newgeometry, however, the price is a \clearpage\newpage

\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage{lipsum}

\begin{document}
\the\textwidth---\the\textheight

\newenvironment{whtext}[1]{%
\newpage\begingroup
\hsize=#1
\vsize=\dimexpr\textheight*\numexpr\hsize/\textwidth\relax
\newgeometry{textheight=\vsize,textwidth=\hsize}
}%
{\endgroup\newpage}

\lipsum[1-10]

\begin{whtext}{15cm}
\the\textwidth---\the\textheight

\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}

\begin{whtext}{10cm}
\the\textwidth---\the\textheight

\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}

\end{document}


• Thanks but i need no package – touhami Feb 6 '15 at 20:23

I think I have an answer

\documentclass[a4paper]{book}
\usepackage{lipsum}

\begin{document}
\the\textwidth---\the\textheight

\makeatletter
\newenvironment{whtext}[1]{%
\newpage\begingroup
\hsize=#1
\vsize=\dimexpr\textheight*\hsize/\textwidth\relax
\textwidth=\hsize
\textheight=\vsize}%
{\endgroup\newpage}
\makeatother

\lipsum[1-10]

\begin{whtext}{15cm}
\the\textwidth---\the\textheight
\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}

\end{document}