Generalmacros: grey text box

LaTeX specific issues not fitting into one of the other forums of this category.
Lagrange
Posts: 5
Joined: Mon Oct 19, 2009 3:32 pm

macros: grey text box

Post by Lagrange »

Hi!

I want to include a grey text box in my code. Fortunately I did find a little macro in the internet, which is doing the job. Unfortunately I am too stupid to use it :(.

Code: Select all

\newcommand{\greybox}{\long\def\greybox#1{%
    \newbox\contentbox%
    \newbox\bkgdbox%
    \setbox\contentbox\hbox to \hsize{%
        \vtop{
            \kern\columnsep
            \hbox to \hsize{%
                \kern\columnsep%
                \advance\hsize by -2\columnsep%
                \setlength{\textwidth}{\hsize}%
                \vbox{
                    \parskip=\baselineskip
                    \parindent=0bp
                    #1
                }%
                \kern\columnsep%
            }%
            \kern\columnsep%
        }%
    }%
    \setbox\bkgdbox\vbox{
        \pdfliteral{0.85 0.85 0.85 rg}
        \hrule width  \wd\contentbox %
               height \ht\contentbox %
               depth  \dp\contentbox
        \pdfliteral{0 0 0 rg}
    }%
    \wd\bkgdbox=0bp%
    \vbox{\hbox to \hsize{\box\bkgdbox\box\contentbox}}%
    \vskip\baselineskip%
}

}
This is the way I tried to include it. If I compile it, I get the following error message:

./Thesis.tex:24:Illegal parameter number in definition of \greybox. }

Can anyone help? The code is from:
http://www.alfredklomp.com/programming/tex/macros/

Thx a lot!

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: macros: grey text box

Post by Stefan Kottwitz »

Hi Lagrange,

welcome to the bord!
Just remove that \newcommand{...} around the \greybox definition. Use it exactly like defined on that web site.

Stefan
LaTeX.org admin
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

macros: grey text box

Post by gmedina »

HI,

the problem comes from enclosing the original definition inside a superfluous \newcommand command. The following simple code works OK:

Code: Select all

\documentclass{article}
\usepackage{lipsum}% just to generate some text

\long\def\greybox#1{%
    \newbox\contentbox%
    \newbox\bkgdbox%
    \setbox\contentbox\hbox to \hsize{%
        \vtop{
            \kern\columnsep
            \hbox to \hsize{%
                \kern\columnsep%
                \advance\hsize by -2\columnsep%
                \setlength{\textwidth}{\hsize}%
                \vbox{
                    \parskip=\baselineskip
                    \parindent=0bp
                    #1
                }%
                \kern\columnsep%
            }%
            \kern\columnsep%
        }%
    }%
    \setbox\bkgdbox\vbox{
        \pdfliteral{0.85 0.85 0.85 rg}
        \hrule width  \wd\contentbox %
               height \ht\contentbox %
               depth  \dp\contentbox
        \pdfliteral{0 0 0 rg}
    }%
    \wd\bkgdbox=0bp%
    \vbox{\hbox to \hsize{\box\bkgdbox\box\contentbox}}%
    \vskip\baselineskip%
}

\begin{document}

\lipsum[1]
\greybox{\lipsum[1]}

\end{document}
By the way, the framed package offers the shaded environment.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Lagrange
Posts: 5
Joined: Mon Oct 19, 2009 3:32 pm

Re: macros: grey text box

Post by Lagrange »

Ok, now I just copied everything - like it is on the web page - into the preamble. Now I can compile the document, but I cannot call the macro.

\greybox{verferf} produces the error message

./chapter3.tex:99:Undefined control sequence. \greybox{verferf}

Is it a problem, that I defined the macro in "Thesis.tex", but I try to call it in "chapter3.tex"?

Thx


@gmedina
I did copy your example into my preamble, but I still get the same error message :(. I even tried to run your example - but it gives the same error message. I do not have the package lipsum.sty, so I just used \greybox{gergerg}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: macros: grey text box

Post by Stefan Kottwitz »

Perhaps show your .log file, you could post it as attachment here.

Stefan
LaTeX.org admin
Lagrange
Posts: 5
Joined: Mon Oct 19, 2009 3:32 pm

Re: macros: grey text box

Post by Lagrange »

sure!
Attachments
Thesis.log
(18.94 KiB) Downloaded 307 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: macros: grey text box

Post by Stefan Kottwitz »

You're using latex format, not pdflatex. The macro uses \pdfliteral commands not allowed in dvi mode. It could work if you compile directly to pdf using pdflatex.

Stefan
LaTeX.org admin
Lagrange
Posts: 5
Joined: Mon Oct 19, 2009 3:32 pm

Re: macros: grey text box

Post by Lagrange »

The problem is that I am working on a linux machine, hence all my pictures are in the eps-format. But yes you are right. If I try to compile gmedina's example with pdflatex it does work. So there is no way to use this macro? :(
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

macros: grey text box

Post by Stefan Kottwitz »

You could use your eps pictures with pdflatex using the epstopdf package.

Stefan
LaTeX.org admin
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

macros: grey text box

Post by gmedina »

Lagrange wrote:...So there is no way to use this macro? :(
Another option, that I've already suggested, would be to use the shaded environment fron the framed package instead of the \greybox command.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply