Hello

This is a LaTeX question more than a LyX one - is there a latex-users list
somewhere? But it's relevant to Lyx because I'm experimenting with LaTeX at
the moment, intending to migrate a whole lot of XML documents into LyX when
I have the necessary classes/layouts working.

Anyway, I'm trying to create an environment which formats its contents in a
box. I have two versions, the second of which (syntax) has a border. The
following is a test document:

------------------------------
\documentclass[12pt]{article}

\usepackage{framed}
\usepackage{xcolor}
\usepackage{alltt}
\usepackage{calc}

\setlength\textwidth {6.5in}
\setlength\evensidemargin {0in}
\setlength\oddsidemargin {0in}
\setlength\parindent {0pt}
\setlength\parskip{\medskipamount}

\definecolor{mybackground}{rgb}{0.85,0.85,0.85}
\definecolor{myborder}{rgb}{0,0,0}

\newsavebox{\mycodebox}
\newenvironment{mycode}{
  \begin{lrbox}{\mycodebox}
    \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule}
      \begin{alltt}
}{
      \end{alltt}
    \end{minipage}
  \end{lrbox}
  \noindent\colorbox{mybackground}{\usebox{\mycodebox}}
}

\newsavebox{\syntaxbox}
\newenvironment{syntax}{
  \begin{lrbox}{\syntaxbox}
    \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule}
      \begin{alltt}
}{
      \end{alltt}
    \end{minipage}
  \end{lrbox}
  \noindent\fcolorbox{myborder}{mybackground}{\usebox{\syntaxbox}}
}

\newcommand{\myvar}[1]{\textit{#1}}
\newcommand{\mykeyword}[1]{\textbf{#1}}

\begin{document}
\section{Sample Box Layouts}
Here's an attempt to show a code fragment:

\begin{mycode}
for \myvar{var1}, \myvar{var2}
do \myvar{something}
\end{mycode}

And a syntax definition:

\begin{syntax}
define \mykeyword{var} as \myvar{something}
\end{syntax}
\end{document}
------------------------------

When I submit this document to LaTeX it tells me
a. that the mycode box is overfull:
  Overfull \hbox (1.8111pt too wide) in paragraph at lines 51--52
  [][][][][][]

b. that the syntax box is underfull:
  Underfull \hbox (badness 10000) in paragraph at lines 57--58

and additionally
c. when I view the output with xdvi I note that the LH border of the syntax
box is missing.

I have three questions.

Firstly, what's wrong with these definitions to cause the under/over-full
warnings?

Secondly, what's happening to the LH border of the fcolorbox?

Thirdly, is there a way of modifying the definitions so that the boxes can
be given an appropriate width for their content rather than extending to the
RH margin? I realize that at the moment the width which I am passing to the
minipage is responsible for this, but I don't know how to tell it to adjust
the width to the actual box content.

Thanks for any help

Cheers
Trevor


Reply via email to