\RequirePackage{etex}
\documentclass[11pt,oneside,a4paper,oldfontcommands,danish,english,article]{memoir}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[widespace]{fourier}

\setlxvchars[\normalfont]

\settypeblocksize{*}{1.3\lxvchars}{1.618}

\setlrmargins{*}{*}{0.7}
\setulmargins{*}{*}{1}
\setlength\marginparwidth{3.5cm}

\checkandfixthelayout


\hfuzz=30pt

\setfootnoterule[\vfill]{3pt}{0.4\columnwidth}{\normalrulethickness}

\usepackage{color}
\usepackage[colorlinks,breaklinks]{hyperref}
\definecolor{linkcolour}{rgb}{0,0.2,0.6}
\definecolor{citecolour}{rgb}{0,0.6,0.2}
\definecolor{urlcolour} {rgb}{0.8,0,0.8}
\definecolor{nicered}{rgb}{.647,.129,.149}


\hypersetup{
  pdftitle={The dlfltxbcodetips package},
  pdfauthor={Copyright \textcopyright\ \number\year\ Lars Madsen},
  linkcolor=linkcolour,citecolor=citecolour,
  filecolor=urlcolour,urlcolor=urlcolour,
  plainpages=false,
}
  
\ifpdf\else\usepackage{breakurl}\fi
\usepackage{memhfixc}

\clubpenalty=300
\widowpenalty=300

\usepackage{microtype}

\usepackage{amsmath,amssymb}
\usepackage[amsmath,thmmarks,framed]{ntheorem}
\usepackage[round]{natbib}

\usepackage{dlfltxbcodetips}
\OverloadUnderscoreInMath

\usepackage[loadsampleconfig]{dlfltxbmarkup}
\renewcommand\felineMarginAdjustment{\RaggedLeft}



\usepackage{dlfltxbmisc}
\usepackage{graphicx}

\chapterstyle{article}

\setsecheadstyle{\normalfont\large\bfseries\raggedright}


\reversemarginpar
\reversesidepartrue

\definecolor{shadecolor}{gray}{0.8}
\theorembodyfont{\normalfont}
\theoremseparator{.}
\def\theoremframecommand{\colorbox{shadecolor}}

\theoremstyle{nonumberplain}

\NewShadedTheorem{caveat}{Caveat}

\NewShadedTheorem{remark}{Remark}

% until dlfltxbsd is released we will have to use the following
% construction

\usepackage{fancyvrb}
\fvset{fontsize=\footnotesize}

\newcommand\verbfile{\jobname.vrb}
\newenvironment{sourcedisplay}{%
\par\vskip0.5\baselineskip\noindent
\VerbatimOut{\verbfile}}{%
\endVerbatimOut%
\noindent
\begin{minipage}{0.48\linewidth}
\VerbatimInput{\verbfile}
\end{minipage}
\hfill
\begingroup%
\begin{minipage}{0.48\linewidth}
\begin{framed}
\input{\verbfile}
\end{framed}
\end{minipage}
\endgroup\vskip0.5\baselineskip}


\newenvironment{Sourcedisplay}{%
\par\vskip0.5\baselineskip\noindent
\VerbatimOut{\verbfile}}{%
\endVerbatimOut%
\noindent
\begin{minipage}{\linewidth}
\VerbatimInput{\verbfile}
\end{minipage}
\par\bigskip\noindent
\begin{minipage}{\linewidth}
\begin{framed}
\input{\verbfile}
\end{framed}
\end{minipage}
\vskip0.5\baselineskip}


\pagestyle{plain}
\newcommand\note[1]{\textcolor{nicered}{\sffamily #1}}


\hyphenation{Provide-PGF-Pages-Four-On-One-With-Space-For-Notes}
\hyphenation{Overload-Underscore-In-Math}

\begin{document}

\title{Code tips from ``Introduktion til \LaTeX''\thanks{Version: 0.2}\\{\normalsize Or just the
    \textsf{\jobname} package}}
\author{Lars Madsen\thanks{Web:
    \url{http://home.imf.au.dk/daleif}\qquad Email: \url{daleif@imf.au.dk}}}
\maketitle

\tableofcontents*

\setsecnumdepth{part}

\chapter{Introduction}
\label{cha:introduction}

In my \LaTeX\ book \citep{ltxb} we present some macros that might be
helpful to the readers.  Some of these extra macros might be useful to
others as well so these macros have been included in the
\markup[nomk,sty]{dlfltxbcodetips} package. The package is published on \textsc{ctan} and the
package is released under the normal lppl license.

The >>\texttt{dlfltxb}<< part of the name simply stands for >>daleif<<
and \LaTeX\ book. The \markup[nomk,sty]{dlfltxbcodetips} package is the first
package in the >>\texttt{dlfltxb}<<-bundle which, over time, will
contain most of the home made packages that I use to create my book
(though not the book source itself).

Some of the macros might be better of included in the
\markup[nomk,sty]{mathtools} package by Morten Høgholm, but he is quite busy
elsewhere at the moment. 

\bigskip

%\newpage
\noindent
\emph{Note:} The macro \verb+\dbx+ will often be used to simulate some
text or mathematical material. 

\setsecnumdepth{section}

\chapter{Extra symbols}
\label{cha:extra-symbols}

\section{\texorpdfstring{A big version of \cs{times}}{A big version of 
    \textbackslash times}}
\label{sec:big-version-cstimes}



A few extra symbols have been created. First of is \markup{bigtimes}
which is a large operator version of \markup[nomk]{times}, but without
having to load special fonts.\footnote{Updated version due to Enrico Gregorio.}
\begin{sourcedisplay}
$\bigtimes_{n=1}^k A_n$
\[ \bigtimes_{n=1}^k A_n \]
\end{sourcedisplay}

\section{Negated up- and downarrows}
\label{sec:negat-up-down}

The package creates \markup{nuparrow} and \markup{ndownarrow} by
rotating and reflecting \markup[nomk]{nrightarrow} and 
\markup[nomk]{nleftarrow}
respectively.\addtocounter{footnote}{-1}\footnotemark
\begin{sourcedisplay}
$ A  \nuparrow B$ \qquad
$ B \ndownarrow C$
\end{sourcedisplay}

\begin{remark}
  The \markup[nomk,sty]{mathdesign} package is incompatible with
  \markup[nomk,sty]{amssymb}, but it does define the symbols we need
  from it to define \cs{nuparrow} and \cs{ndownarrow}. Use
  \begin{syntax}
    \verb|\usepackage[noamssymb]{dlfltxbcodetips}|
  \end{syntax}
  to disable the autoloading of \markup[nomk,sty]{amssymb}, and
  remember to load \markup[nomk,sty]{dlfltxbcodetips} \emph{after}
  \markup[nomk,sty]{mathdesign}. 
\end{remark}


\chapter{Fun with theorems}
\label{cha:fun-with-theorems}

\section{Shaded or framed theorems with the ntheorem package}
\label{sec:shaded-theorems-with}

The \markup[nomk,sty]{ntheorem} pacakge can create shaded or framed
theorems, but they take up to much space (in my opinion).  So we make
our own macro \markup{NewShadedTheorem}.  It has exactly the same
syntax as the ordinary \markup[nomk]{newtheorem}. Requirements: the
\markup[nomk,sty]{framed}, \markup[nomk,sty]{ntheorem} (loaded with
the \texttt{framed} option), and \markup[nomk,sty]{color} or
\markup[nomk,sty]{xcolor}. You will have to redefine
\markup{theoremframecommand} to get a background color or a
frame. This package initialises \markup[nomk]{theoremframecommand} to
do nothing.
\begin{caveat}
  The theorem environment constructed will not have a stared companion
  as \markup[nomk,sty]{ntheorem}s normal \markup[nomk]{newtheorem} does.
\end{caveat}
\begin{sourcedisplay}
\def\theoremframecommand{\fboxsep=10pt\fbox}
\NewShadedTheorem{sthm}{Theorem}[chapter]
\def\theoremframecommand{%
\colorbox{red}}
\NewShadedTheorem{slemma}[sthm]{Lemma}
\newtheorem{prop}[sthm]{Proposition}
\begin{sthm}
  normal test.
\end{sthm}
\begin{slemma}
  a lemma.
\end{slemma}
\begin{prop}
  a theorem with no background.
\end{prop}
\end{sourcedisplay}

\theoremstyle{plain}
\newtheorem{thm}{Theorem}

\section{Theorems that start with a list}
\label{sec:theorems-that-start}

A theorem that starts with a list looks odd because the first item
comes directly after the heading.\footnote{Depends on the
  configuration.}
\begin{sourcedisplay}
\begin{thm}
  \begin{enumerate}
  \item \dbx[2cm]
  \item \dbx[2cm]
  \item \dbx[2cm]
  \end{enumerate}
\end{thm}
\end{sourcedisplay}
The macro \markup{InsertTheoremBreak} helps.
\begin{sourcedisplay}
\begin{thm}
  \InsertTheoremBreak
  \begin{enumerate}
  \item \dbx[2cm]
  \item \dbx[2cm]
  \item \dbx[2cm]
  \end{enumerate}
\end{thm}
\begin{thm}
  \InsertTheoremBreak*
  \begin{enumerate}
  \item \dbx[2cm]
  \item \dbx[2cm]
  \item \dbx[2cm]
  \end{enumerate}
\end{thm}
\end{sourcedisplay}
\noindent The un-stared version remove the space above the list, the
stared version does not.

\begin{caveat}
  If the theorem comes too close to a page break it is quite likely
  that the page break will end up between the theorem header and the
  start of the list.
\end{caveat}

\chapter{Various features regarding alignment}
\label{cha:vari-feat-regard}



\section{Alignment with material encased in delimiters on different lines}
\label{sec:alignm-with-mater}

Swanson also recommends that if one has material encased with
delimiters and the delimiters are on different lines, then if space
permits, the material should be indented such that the relationship is
evident. Usually we would use a \markup[nomk]{phantom} to do this,
such as in the next example.
\begin{sourcedisplay}
\begin{align*}
  \dbx[5mm]&= \dbx[5mm]\bigl[{} \dbx[3cm]\\
   &\phantom{=\dbx[5mm]\bigl[{}}
   \times \dbx[3cm]{}\\
   &\phantom{=\dbx[5mm]\bigl[{}}
   - \dbx[3cm]{}\bigr]\\
   &=\dbx[3cm]
\end{align*}
\end{sourcedisplay}
The problem with this is that it gets tedious and prone to human
error. How about instead maintaining a stack of material determining
the indentation together with tools to reset, add to and pop the
stack. For this you can use the following macros
\begin{syntax}
  \markup{MathIndent}
  \markup{SetMathIndent}\marg{math code}
  \markup{AddtoMathIndent}\marg{math code}
  \markup{PopMathIndent}
  \markup{PopMathIndent*}
\end{syntax}
\markup[nomk]{MathIndent} is used to set a space corresponding to the
current indentation saved on the stack. \markup[nomk]{SetMthIndent}
takes its argument and saves it on the stack, calculates the current
math indent length and ends by typesetting the given argument, i.e. no
need to copy anything. Similarly the \markup[nomk]{AddtoMathIndent}
adds it argument to the stack and adds the length of it to the saved
math indent. So instead of copying code, now we simply encase it with
either \markup[nomk]{SetMathIndent} (for the initialisation) or
\markup[nomk]{AddtoMathIndent}. \markup[nomk]{PopMathIndent} is
similar to \markup[nomk]{MathIndent}, in that it sets a blank space
corresponding to the contents of the stack after we have popped off
the top item. \markup[nomk]{PopMathIndent*} pops the stack but does
\emph{not} set any space.


Now, an illustrative example might be in order:
\begin{Sourcedisplay}
\begin{align*}
\dbx ={} & \SetMathIndent{\dbx[1cm] \Bigl[} \dbx[6cm]  \\
   & \MathIndent   + \dbx[7cm]  \\
   & \MathIndent 
   \AddtoMathIndent{{} + \dbx \Bigl\{}
   \AddtoMathIndent{\dbx[2cm] + \Bigl(} \dbx[4cm] \\
   & 
   \MathIndent + \dbx[4cm] \Bigr) \\
   & \PopMathIndent + \dbx[6cm] \Bigr\} \\
   & \PopMathIndent + \dbx[6cm] \Bigr]
\end{align*}
\end{Sourcedisplay}
Notice the dual use of \markup[nomk]{AddtoMathIndent} such that we can
return to the indentation set by the >>\texttt{\{}<<.

Of course, non-balanced \markup[nomk]{left}--\markup[nomk]{right}
constructions may not be used.




\chapter{Declaring sets}
\label{cha:declaring-sets}

\emph{This still needs some work}


It is a good idea to avoid the one (or two) letter shortcuts for sets
etc., e.g.\ \verb+\R+ for \verb+\mathbb{R}+, it can cause problems
when co-writing articles with people with other naming habits. 

To help with this we provide 
\begin{syntax}
\markup{DeclareMathSet}\oarg{options}\marg{identifier}
\end{syntax}
By default it can be used as
\begin{Sourcedisplay}
\DeclareMathSet{R}% => \numbersR = \mathbb{R}
$ \numbersR $  
\end{Sourcedisplay}
But we have several options to change things. Options
(\Arg{key}=\Arg{value} style, note that \Arg{identifier} is what is
given to the formating macro).
\begin{description}\firmlist
\item[format] the macro used to format the output, default: \verb|\mathbb|
\item[name] this defaults to \Arg{identifier}, but can be used to
  change a part of the macro name,
  e.g. \verb+\DeclareMathSet[name=Cat,format=\matcal]{C}+ results in
  \verb+\setCat=\mathcal{C}+. 
\item[prefix] this defaults to \verb+set+, but one might want to use
  \begin{syntax}
    \verb+\DeclareMathSet[prefix=group,format=\mathrm]{U}+
  \end{syntax}
to get
  \verb+\groupU+, the unitary group.
\item[overwrite] boolean, if true, then you can overwrite an existing
  macro, otherwise it will throw an error.
 
\end{description}
Note that for sets it is not a good idea to declare them as math
operators, as some mathematical operations take sets as their
argument, so the spacing before an operator would be wrong in that
case.

\note{Note that this will also be added to the mathtools package, and
  then removed from this package}

\chapter{Misc}
\label{cha:misc}

\section{Additional layout for the \textsf{pfgpages} package}
\label{sec:addit-layo-textsfpfg}

The macro \markup{ProvidePGFPagesFourOnOneWithSpaceForNotes} will
activate a \linebreak >>\verb*+4 on 1 with space for notes+<< layout to be used
with the \markup[sty,nomk]{pgfpages} package. It is basically the same
as the >>\verb*+8 on 1+<< layout but leaving the second column empty
for reader to fill in their own notes.

\section{Overloading \texttt{\_} in math-mode}
\label{sec:overl-texttt_-math}

Placing \markup{OverloadUnderscoreInMath} in the preamble will
overload the \texttt{\_} character in math-mode such that 
\begin{Sourcedisplay}
\[
   X_{ab} = X_|max|  
\]
\end{Sourcedisplay}
that is \verb+_|...|+ is that same as \verb+_{\textup{...}}+. 

\bibliographystyle{plainnat}
\bibliography{package_doc}



\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% TeX-source-specials-mode: t
%%% TeX-PDF-mode: nil
%%% End: 















