# Re: How to add tips/warnings/notes to a document

On 12/28/2009 02:38 PM, Steve Litt wrote:

On Monday 28 December 2009 13:50:39 rgheck wrote:

On 12/28/2009 11:02 AM, Steve Litt wrote:

On Monday 28 December 2009 06:18:25 Pieter Claassen wrote:

I am trying to build a custom style/minipage environment for
comments/warnings/tips. However, many other collaborators in the
documentation project are not Lyx/Latex boffins so I cannot really ask
them to install custom extensions to Lyx/Latex.

Currently I use a Box with a minipage environment, but this has to be
customised based on whether it is a tip/warning or note that I am
producing.

What is the easiest way to achieve this?

Thanks,
Pieter

Hi Pieter,

I've done it numerous ways. The best way I did it was to create a basic
LaTeX command called "callouttitleL" converted to LyX command
CalloutTitle and LaTeX environment callouttextL converted to LyX
environment CalloutText. Using these, you can have a text with an
arbitrary title. Three such arbitrary titles are "Note", "Tip" and
"Warning". I created custom LaTeX and LyX environments for those special
cases.

Here's the code:

You can put the preamble code into the layout, and then you only have to
deal with one file: the module.

Hi Richard,

I'm not sure what you mean. The only file I deal with is my layout file.


You have to paste the LaTeX separately into the LyX file.


If you mean putting a Preamble/EndPreamble pair inside a LyX environment, I
never do that because it can fail at the worst possible time. I documented
that a year or two ago on the lyx-users list. I always keep my LaTeX defs and
my LyX defs completely separate, with only the LatexName from the LyX def


I'd be interested to know how this fails, when it does. The only issue we tend to see like this concerns conflicts between user-defined stuff and LyX-inserted stuff. The preamble stuff itself just gets output verbatim whenever the relevant style is used, so I think it is fairly foolproof. Indeed, the only difference between putting it into the document preamble and putting into the layout is exactly when it gets output---and the fact that preamble material associated with a given style is output only if that style is used. There are some tricks here regarding styles that depend on other styles. See the attached.


I have to learn how to use modules before my next book. Layouts have been
working well for me, but I understand modules are even better.


I'm attaching a module based on what you posted. As you will see, there's nothing to it. It's just a layout file, except for the header information. Put it in ~/.lyx/layouts/, reconfigure, and then look under Document>Settings>Modules. Select it and there you go.

Richard


#\DeclareLyXModule{Callout}
#DescriptionBegin
#Adds styles for various sorts of minipages, for titles, warnings, etc.
#DescriptionEnd

#Author: Steve Litt

Format 11

Style CalloutTitle
Font
Series  Bold
Size Larger
EndFont
LatexName       callouttitleL
LatexType       Command
Align                 Center
Preamble
\newcommand{\callouttitleL}[1]{\def\callouttitleT{#1}}
EndPreamble
End

Style CalloutText
LatexType             Environment
LatexName             callouttextL
LeftMargin            MMMMMM
RightMargin           MMMMMM
ParIndent             MMM
TopSep                1.4
ItemSep               0.7
ParSep                0.7
BottomSep             0.7
Align                 Block
AlignPossible         Block

Font
Series               Medium
Size                 Normal
Shape                Italic
EndFont
DependsOn             CalloutTitle
Preamble
\newenvironment{callouttextL}
{%
~\\[-0.25in]%
\setlength\fboxsep{4pt}%
{\centering\Large\callouttitleT\\[0.2cm]}%
\raggedright%
\setlength\parindent{16pt}%
}%
{%
\par
}%
EndPreamble
End

Style Warning
LatexType             Environment
LatexName             warningL
LeftMargin            MMMMMM
RightMargin           MMMMMM
ParIndent             MMM
TopSep                1.4
ItemSep               0.7
ParSep                0.7
BottomSep             0.7
Align                 Block
AlignPossible         Block
LabelType             Centered_Top_Environment
LabelString           "Warning"

Font
Series               Medium
Size                 Normal
Shape                Italic
EndFont
Preamble

\newenvironment{warningL}{\callouttitleL{Warning}\begin{callouttextL}}
{\end{callouttextL}}
EndPreamble
DependsOn             CalloutText
End

Style Tip
LatexType             Environment
LatexName             tipL
LeftMargin            MMMMMM
RightMargin           MMMMMM
ParIndent             MMM
TopSep                1.4
ItemSep               0.7
ParSep                0.7
BottomSep             0.7
Align                 Block
AlignPossible         Block
LabelType             Centered_Top_Environment
LabelString           "Tip"

Font
Series               Medium
Size                 Normal
Shape                Italic
EndFont
Preamble
\newenvironment{tipL}{\callouttitleL{Tip}\begin{callouttextL}}
{\end{callouttextL}}
EndPreamble
DependsOn             CalloutText
End

Style Note
LatexType             Environment
LatexName             noteL
LeftMargin            MMMMMM
RightMargin           MMMMMM
ParIndent             MMM
TopSep                1.4
ItemSep               0.7
ParSep                0.7
BottomSep             0.7
Align                 Block
AlignPossible         Block
LabelType             Centered_Top_Environment
LabelString           "Note"

Font
Series               Medium
Size                 Normal
Shape                Italic
EndFont
Preamble
\newenvironment{noteL}{\callouttitleL{Note}\begin{callouttextL}}
{\end{callouttextL}}
EndPreamble
DependsOn             CalloutText
End