在新命令或新环境中双重列出

在新命令或新环境中双重列出

我正在尝试使用新命令来简化我所记的日记。

以下是我的日记的示例:

\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}

您可能注意到我有两个主要结构:

  1. 我在家工作的日子(上面代码中的第一种情况)
  2. 我在办公室工作的日子(上面代码中的第二种情况)

而对于第二个,我定义了一个新命令,如下所示

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

我将其称为

\office{Day Month Year}

我好像无法解决在家办公的日子的问题。

到目前为止我达到的最好成绩是:

\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}
}

然后按如下方式工作

\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}

我想要实现的目标是拥有一个新命令或一个新环境,如下所示:

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

或者,在新环境中

\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}

特殊情况如下:

  1. 我在家工作的日子,但只在早上
  2. 我请病假的日子
  3. 公共假期
  4. 我休假的日子

对于情况 2、3 和 4,我可能会考虑定义一些新命令,就像办公室工作的情况一样。

编辑

这是我目前最好的尝试

\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}

总结

基本上,我试图将 2 个自定义长度的 itemize 放入一个新命令或一个新环境中

答案1

这里有一些想法,也许你可以用一些。

  • 不要使用itemize,而是将活动格式化为彼此独立的。这样您就不必担心启动和结束环境。
  • 只要有可能,使用宏可能比使用环境更容易,因为这样可以避免使用结束标记。
  • 下面有四种标记活动的方法。它们的区别在于活动划分的方式。
    • \ActivityA\macro- 行结束
    • \ActivityB: \macro-- 空行(或 \par)
    • \ActivityC\macro{——}
    • ActivityD\begin{env}——\end{env}
  • 将标记与格式分开可能会很方便。

在此处输入图片描述

\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}

相关内容