3

I am trying to simplify a sort of diary I am keeping by using newcommand.

Here is a sample of what my diary looks like:

\documentclass{article}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}

% Related to math
\usepackage{amsmath,amssymb,amsfonts,amsthm}

% blindtext (Lorem ipsum...)
% \usepackage{blindtext}

\title{\Huge{My Title}}
\author{\huge{Myself}}
\date{\Large{\today}}

\begin{document}
\maketitle
\section*{Day Month Year} 
    \subsection*{morning: start:stop}
    \begin{itemize}
        \item activity 1,
        \item activity 2,
        \item activity 3.
    \end{itemize}

    \subsection*{afternoon: start:stop}
    \begin{itemize}
        \item activity 1,
        \item activity 2.
    \end{itemize}

\section*{Day Month Year} 
    \subsection*{whole day:}
    \begin{itemize}
        \item Work at the office.
    \end{itemize}

\end{document}

As you may notice I have two main structure:

  1. the days when I work at home (first case in the code above)
  2. the days when I work at the office (second case in the code above)

While for the second I have defined a newcommand as follows

\newcommand{\office}[1]{%
\section*{#1}
\subsection*{whole day:}
\begin{itemize}
\item{Work at the office.}
\end{itemize}}

which I conveniently call as

\office{Day Month Year}

I seem not to be able to solve the problem of the days when I work at home.

So far the best I have reached is:

\newenvironment{smartworking}[1]{%
\section*{#1}
\newcommand{\morning}[2]{\subsection*{morning: ##1-##2}}
\newcommand{\afternoon}[2]{\subsection*{afternoon: ##1-##2}}
\newcommand{\activ}[1]{ \item{##1} }
\begin{itemize}
}
{
\end{itemize}
}

which then works as follows

\begin{smartworking}{Martedì 1 Dicembre 2020}
    \morning{09:00}{12:30}
        \activ{activity 1}
        \activ{activity 2}
    \afternoon{14:00}{17:30}
        \activ{activity 1}
        \activ{activity 2}
\end{smartworking}

What I am trying to achieve is to have either a newcommand or a newenvironment to use as follows:

\smartworking{day}{start am}{stop am}{start pm}{stop pm}
morning activity 1
morning activity 2
% some interruption
afternoon activity 1
afternoon activity 2

or, in the case of newenvironment

\begin{smartworking}{day}{start am}{stop am}{start pm}{stop pm}
morning activity 1
morning activity 2
% some interruption
afternoon activity 1
afternoon activity 2
\end{smartworking}

The peculiar cases are:

  1. days when I work at home but only in the morning
  2. days when I am on sick leave
  3. days when there are public holidays
  4. days when I am on holiday

for cases 2, 3, and 4 I might consider defining some new commands like for the case of the work at the office.

EDIT

This is as of now my best try

\documentclass{article}
    % General document formatting
    \usepackage[margin=0.7in]{geometry}
    \usepackage[parfill]{parskip}
    \usepackage[utf8]{inputenc}
    \usepackage[italian]{babel}    

    % Related to math
    \usepackage{amsmath,amssymb,amsfonts,amsthm}
    
    % blindtext (Lorem ipsum...)
    % \usepackage{blindtext}    


    \newenvironment{activities}{
    \newcommand{\activ}[1]{\item[]{##1}}
    \begin{itemize}
    }
    {
    \end{itemize}
    }    

    \newcommand{\smartworking}[1]{\section*{#1}}
    \newcommand{\morning}[2]{\subsection*{morning: #1-#2}}
    \newcommand{\afternoon}[2]{\subsection*{afternoon: #1-#2}}    

    \newcommand{\office}[1]{%
    \section*{#1}
    \subsection*{whole day:}
    \begin{activities}
    \activ{Work at the office.}
    \end{activities}}    

    \newcommand{\sick}[1]{%
    \section*{#1}
    \subsection*{whole day:}
    \begin{activities}
    \activ{Sick leave.}
    \end{activities}}    

    \newcommand{\holidays}[1]{%
    \section*{#1}
    \subsection*{whole day:}
    \begin{activities}
    \activ{Hilday.}
    \end{activities}}    

    \newcommand{\leave}[1]{%
    \section*{#1}
    \subsection*{whole day:}
    \begin{activities}
    \activ{Vacation.}
    \end{activities}}    

\begin{document}
    \smartworking{Day Month Year}
        \morning{start am}{stop am}
            \begin{activities}
                \activ{activity 1}
                \activ{activity 2}
            \end{activities}
        \afternoon{start pm}{stop pm}
            \begin{activities}
                \activ{activity 1}
                \activ{activity 2}
            \end{activities}    

    \office{Day Month Year}    

    \sick{Day Month Year}    

    \leave{Day Month Year}    

    \holidays{Day Month Year}
\end{document}

TL;DR

Basically, I am trying to put 2 custom-length itemize inside a newcommand or a newenvironment

2
  • One goal of your endeavor seems clear (and reasonable): You want to hide the concrete formatting of the items and specify it only in the preamble. What's not so clear: how readable do you want the source file to be (at the expense of safety regarding markup mistakes and ambiguities)? There is a spectrum of solutions along the line implicit vs explicit markup. You can use minimal indicators (like an empty line or single character ) as significant for the interpretation, like markdown syntax. Or you can add begin and end markers for every structure, or wrap it into a command etc.
    – gernot
    Dec 22, 2020 at 12:50
  • Good point. Actually, I would like to have a command for each case, thus the "office", "sick", "leave" and "holidays" work quite good. I would also have something similar for the regular day, but I can't wrap my head around the most efficient solution to do that.
    – brodegon
    Dec 22, 2020 at 13:19

1 Answer 1

3

Here are some ideas, maybe you can use some.

  • Don't use itemize, but format activities independently from each other. Then you don't have to worry about starting and ending the environment.
  • It's probably easier to use macros instead of environments whenever possible, since you avoid the closing markup.
  • Below you find four possibilities to tag activities. They differ in the way the activity is delimited.
    • \ActivityA: \macro -- end-of-line
    • \ActivityB: \macro -- empty line (or \par)
    • \ActivityC: \macro{ -- }
    • ActivityD: \begin{env} -- \end{env}
  • It may be convenient to separate markup from formatting.

enter image description here

\documentclass{article}

% FORMATTING
\newcommand\formatDay[1]{\section*{#1}}
\newcommand\formatPartOfDay[1]{\subsection*{#1}}
\newcommand\formatActivity[1]{%
  \noindent
  \makebox[5mm][c]{\textbullet}%
  \parbox[t]{\dimexpr\textwidth-5mm}{\strut#1\strut}%
  \par
}

% MARKUP
\newcommand\AnotherDay[1]{\formatDay{#1}}
\newcommand\PartOfDay[1]{\formatPartOfDay{#1}}
\newcommand\Morning[2]{\PartOfDay{Morning, #1--#2}}
\newcommand\Afternoon[2]{\PartOfDay{Afternoon, #1--#2}}

% \ActivityA terminated by end-of-line
\newcommand\ActivityA{\bgroup\catcode`\^^M=12 \ActivityAx}
\newcommand\ActivityAx{}
{\catcode`\^^M=12 %
 \gdef\ActivityAx#1^^M{\egroup\formatActivity{#1}}%
}

% \acticityB terminated by empty line
\newcommand\ActivityB{}
\def\ActivityB#1\par{\formatActivity{#1}}

% \ActivityC text wrapped in braces
\newcommand\ActivityC[1]{\formatActivity{#1}}

% environment ActicityD
\usepackage{environ}
\NewEnviron{ActivityD}{\formatActivity{\BODY}}

% SHORTCUTS

\newcommand\Office[1]{%
  \AnotherDay{#1}
  \PartOfDay{Whole Day}
  \ActivityC{Work at the office.}
}
\newcommand\Sick[1]{%
  \AnotherDay{#1}
  \PartOfDay{Whole Day}
  \ActivityC{Sick.}
}
 
\begin{document}
\AnotherDay{22 December 2020}

\Morning{10}{12}
\ActivityA Some long activity taking multiple lines, but which may not be interrupted by end of lines in the input.

\ActivityB Some long activity taking multiple lines
which may be spread across several lines in the input
but which has to end with an empty line.

\Afternoon{14}{19}

\ActivityC{Conventional macro, may spread
  several lines in the input.

  May even contain empty lines or par commands.\par
  Third paragraph.}

\begin{ActivityD}
  Environment, activity may spread
  several lines in the input.

  May even contain empty lines or par commands.\par
  Third paragraph.
\end{ActivityD}

\Office{23 December 2020}

\Sick{24 December 2020}    

\end{document}
2
  • Yeah, this really does it. However, I am wondering what do you mean by "It may be convenient to separate markup from formatting." Looks like you did it already, am I right?
    – brodegon
    Dec 22, 2020 at 17:25
  • 1
    @brodegon I just wanted to highlight the relevant aspects. Yes, I already tried to separate markup and formatting.
    – gernot
    Dec 22, 2020 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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