Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to make a diary that will have the following format

  1. Each entry will be inside a colored box
  2. Each entry will have a title with the date and an optional title
  3. I want the possibility to add notes on the side(preferably at the right one) in a specific line of an entry. The notes will be on a seperate colored box.

I searched the tex.se and found two codes to achieve this. The first one comes from Gonzalo Medina's answer on create a framed environment for a margin note

His way inputs a note on the left side and I believe it would be better if the notes were on right side.

For 1 and 2, I believe that ferahfeza gave a prety answer on using latex to keep a diary however there are some points that are not working because he is probably missing a lot of code.

The idea is to have a diary.tex(that contains the definition of a newenvironment) file which will be inputed in a main file.

My final output would be a combination of those two

enter image description here

My code is

diary.tex

\newcounter{diary}
\renewcommand{\thediary}{\arabic{diary}}
\newenvironment{diary}[2]
{\par\medskip\refstepcounter{diary}%
\hbox{%
\fboxsep=\the\sidebar\hspace{-\envborder}\hspace{-.5\sidebar}%
\colorbox{orange}{%
\hspace{\envborder}\footnotesize\sffamily\bfseries%
\textcolor{white}{{#1}\ {#2}\enspace\thediary\hspace{\envborder}}
%\today % Print date in header of frame
}}}{\vspace{0.5cm}}

The main file is the following

\documentclass{article}

\usepackage[lmargin=5cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{ragged2e}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{marginnote}
\usetikzlibrary{calc}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{framed}
\usepackage{datetime}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}

\reversemarginpar

\newsavebox\mybox
\newlength\BoxHt

\newcommand\caution[2][-2.2\baselineskip]{%
\begin{lrbox}{\mybox}
\parbox{\marginparwidth}{#2}
\end{lrbox}%
\settoheight\BoxHt{\usebox\mybox}%
\raisebox{\BoxHt}[0pt][0pt]{\marginnote{%
  \begin{mdframed}[
    userdefinedwidth=\marginparwidth,
    innerleftmargin=3pt,
    innerrightmargin=3pt,
    linecolor=BrickRed,
    frametitle=\colorbox{white}{\space Caution\space},
    frametitlefont=\color{BrickRed}\sffamily,
    innertopmargin=10pt,
    frametitleaboveskip=-\ht\strutbox,
    frametitlebelowskip=-\ht\strutbox,
    frametitlealignment=\raggedright,
    singleextra={\fill[BrickRed] let \p1=(P), \p2=(O)  in 
    ( $ (P|-0,0.5*\y2+0.5*\y1) + (0,-4pt) $ ) -- +(4pt,4pt) -- +(0,8pt) -- cycle;}
]\RaggedRight\small#2\end{mdframed}}[#1]}}


\input{diary}


\begin{document}

\begin{diary}{}{14.07.2013}
\lipsum*[3-4]\caution{\lipsum[2]}\lipsum[3-5]
\end{diary}

Some test text\caution{Some text goes here just to illustrate the command}

\lipsum[4-5].\caution{Not forget to do this} This is a line that really needs some caution. But now it's time to move on to the next paragraph. \lipsum[1]

\end{document}

My output is the following

enter image description here

How to achieve the desired output?

EDIT

I tried to achieve the colored background using mdframed in a new command, \note with 3 arguments. The new diary.tex is

\mdfdefinestyle{MyFrameBlue}{%
    linecolor=blue!20!white,
    outerlinewidth=0pt,
    roundcorner=0pt,
    innertopmargin=-15pt,
    innerbottommargin=-5pt,
    innerrightmargin=0pt,
    innerleftmargin=0pt,
    backgroundcolor=blue!20!white}
\newcounter{diary}
\renewcommand{\thediary}{\arabic{diary}}
\newenvironment{diary}[2]
{\par\medskip\refstepcounter{diary}%
\hbox{%
\setlength{\fboxsep}{5pt}
\colorbox{orange}{%
\hspace{2pt}\footnotesize\sffamily\bfseries%
\textcolor{white}{\thediary. \ {#1}\ {#2}\enspace\hspace{2pt}}
}}}{\vspace{0.5cm}}
\newcommand{\note}[3]{\begin{mdframed}[style=MyFrameBlue]
                          \begin{diary}{#1}{#2}{\vspace{0.5cm} #3}\end{diary}
                      \end{mdframed}
                      }

The thing is that when I use \caution{} inside the diary environment, the background color is adopted.

\note{}{14.11.2013}{This is the \caution{Watch the traps!} first note}

enter image description here

share|improve this question
1  
Oh lord. Keeping diary should be a happy thing. You use LaTeX to do it? [facepalm] –  Sibbs Gambling Nov 14 '13 at 16:30
    
@Thanos, I updated my previous answer here tex.stackexchange.com/questions/68525/… –  ferahfeza Nov 14 '13 at 16:36
1  
@perfectionm1ng: There are also research diaries, high heel princess... –  Thanos Nov 14 '13 at 16:36
    
@ferahfeza: Thank you very much for your comment. The thing is tht I need the box in the side note, as well as the little arrow indicating at which line the note is reffering to. In addition, I think it would be more straight forward not to use the diary entries in a seperate file. Is there a technical reason to do that? Thank's once again for your effort! –  Thanos Nov 14 '13 at 16:41
    
@Thanos: Your welcome. I use separate file because for easy archiving of diaries. It's arbitrary, no technical reason. I'm sorry for boxing, because my time is very limited for writing some documents. –  ferahfeza Nov 14 '13 at 16:50

1 Answer 1

up vote 2 down vote accepted

After ferahfeza updated his answer on using latex to keep a diary the diary.tex is updated like that

diary.tex

 \newlength\sidebar
 \newlength\envrule
 \newlength\envborder
 \setlength\sidebar{1.5mm}
 \setlength\envrule{0.4pt}
 \setlength\envborder{2mm}

\makeatletter
 \long\def\fboxs#1{%
   \leavevmode
   \setbox\@tempboxa\hbox{%
     \color@begingroup
       \kern\fboxsep{#1}\kern\fboxsep
     \color@endgroup}%
   \@frames@x\relax}
 \def\frameboxs{%
   \@ifnextchar(%)
     \@framepicbox{\@ifnextchar[\@frameboxs\fboxs}}
 \def\@frameboxs[#1]{%
   \@ifnextchar[%]
     {\@iframeboxs[#1]}%
     {\@iframeboxs[#1][c]}}
 \long\def\@iframeboxs[#1][#2]#3{%
   \leavevmode
   \@begin@tempboxa\hbox{#3}%
     \setlength\@tempdima{#1}%
     \setbox\@tempboxa\hb@xt@\@tempdima
          {\kern\fboxsep\csname bm@#2\endcsname\kern\fboxsep}%
     \@frames@x{\kern-\fboxrule}%
   \@end@tempboxa}
 \def\@frames@x#1{%
   \@tempdima\fboxrule
   \advance\@tempdima\fboxsep
   \advance\@tempdima\dp\@tempboxa
   \hbox{%
     \lower\@tempdima\hbox{%
       \vbox{%
         %\hrule\@height\fboxrule
         \hbox{%
          \vrule\@width\fboxrule
           #1%
           \vbox{%
             \vskip\fboxsep
             \box\@tempboxa
             \vskip\fboxsep}%
           #1%
           }%\vrule\@width\fboxrule}%
         }%\hrule\@height\fboxrule}%
                           }%
         }%
 }
 \def\esefcolorbox#1#{\esecolor@fbox{#1}}
 \def\esecolor@fbox#1#2#3{%
   \color@b@x{\fboxsep\z@\color#1{#2}\fboxs}{\color#1{#3}}}
 \makeatother


 \definecolor{exampleborder}{HTML}{FE642E}
 \definecolor{examplebg}{HTML}{CEF6EC}
 \definecolor{statementborder}{rgb}{.9,0,0}
 \definecolor{statementbg}{rgb}{1,1,1}

 \newenvironment{eseframed}{%
   \def\FrameCommand{\fboxrule=\the\sidebar  \fboxsep=\the\envborder%
   \esefcolorbox{exampleborder}{examplebg}}%
   \MakeFramed{\FrameRestore}}%
  {\endMakeFramed}

\newcounter{diary}
\renewcommand{\thediary}{\arabic{diary}}

 %%% CODE ENVIRONMENT. PUT TEXT INTO COLORED FRAME %%%
 \newenvironment{diary}[2]
 {\par\medskip\refstepcounter{diary}%
 \hbox{%
 \fboxsep=\the\sidebar\hspace{-\envborder}\hspace{-.5\sidebar}%
 \colorbox{exampleborder}{%
 \hspace{\envborder}\footnotesize\sffamily\bfseries%
 \textcolor{white}{{#1}\ {#2}\enspace\hspace{\envborder}}
 }
 }
 \nointerlineskip\vspace{-\topsep}%
 \begin{eseframed}\noindent\ignorespaces%
 }
 {\end{eseframed}\vspace{-\baselineskip}\medskip}

In the main.tex Gonzalo Medina's code will be added, that will give the sidenotes with the pointing arrow, inside a colored box.

\documentclass{article}

\usepackage[lmargin=5cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{ragged2e}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{marginnote}
\usetikzlibrary{calc}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{framed}
\usepackage{datetime}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}

\reversemarginpar

\newsavebox\mybox
\newlength\BoxHt

\newcommand\caution[2][-2.2\baselineskip]{%
\begin{lrbox}{\mybox}
\parbox{\marginparwidth}{#2}
\end{lrbox}%
\settoheight\BoxHt{\usebox\mybox}%
\raisebox{\BoxHt}[0pt][0pt]{\marginnote{%
  \begin{mdframed}[
    userdefinedwidth=\marginparwidth,
    innerleftmargin=3pt,
    innerrightmargin=3pt,
    linecolor=BrickRed,
    frametitle=\colorbox{white}{\space Caution\space},
    frametitlefont=\color{BrickRed}\sffamily,
    innertopmargin=10pt,
    frametitleaboveskip=-\ht\strutbox,
    frametitlebelowskip=-\ht\strutbox,
    frametitlealignment=\raggedright,
    singleextra={\fill[BrickRed] let \p1=(P), \p2=(O)  in 
    ( $ (P|-0,0.5*\y2+0.5*\y1) + (0,-4pt) $ ) -- +(4pt,4pt) -- +(0,8pt) -- cycle;}
]\RaggedRight\small#2\end{mdframed}}[#1]}}


\input{diary}

\begin{document}

\begin{diary}{}{14.07.2013}
\lipsum*[3-4]\caution{\lipsum[2]}\lipsum[3-5]
\end{diary}

\end{document}

The output is

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.