summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/mindflow/mindflow.dtx
blob: 9f7e2adc98f08bacdeba228baea66a7f8b6acf0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
% \iffalse meta-comment
%
% Copyright (C) 2021 by Jinwen XU 
% -------------------------------
% 
% This file may be distributed and/or modified under the conditions of the LaTeX
% Project Public License, either version 1.3 of this license or (at your option)
% any later version. The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX version
% 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{mindflow.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{mindflow}
%<*package>
    [2021/03/11 Mindflow environment]
%</package>
%
%<*driver>
\documentclass{article}
\usepackage{doc}
\usepackage[a4paper,top=1.2in,bottom=1.2in,left=1.5in,right=1.2in]{geometry}
\usepackage{titling}
\setlength{\droptitle}{-.5in}
\usepackage[linenumber,rightmarker]{mindflow}
\usepackage{enumitem}
\setlist{noitemsep}
\usepackage{newpxtext}
\usepackage{blindtext}
\usepackage{parskip}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{mindflow.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{119}
%
% \GetFileInfo{mindflow.dtx}
%
%
% \title{The {\normalfont\textsf{mindflow}} package}
% \author{\scshape Jinwen Xu}
% \date{\filedate}
%
% \maketitle
%
% \section{Introduction}
%
% The \textsf{mindflow} package provides you a way to write your ideas,
% annotations or writing plans. 

% For example (with option
% \verb|linenumber| and \verb|rightmarker|):
% \begin{mindflow}
%     What to write next:
%     \begin{itemize}
%         \item usage;
%         \item some internal macros;
%         \item an example maybe;
%         \item the complete code.
%     \end{itemize}
% \end{mindflow}
% You can also add line numbers to the other part of your document in the usual way.
% Line numbers within the \textsf{mindflow} environments are independent from
% those of the main text.
%
% \section{Usage}
%
% Simply load the package with \verb|\usepackage{mindflow}|. By default
% it has no line numbers or markers. You can use the following options:
%
% \begin{tabular}{ll}
%     \verb|linenumber| & Enable line numbers\\
%     \verb|leftmarker| & Enable left marker, by default it is a ``\verb|*|''\\
%     \verb|rightmarker| & Enable right marker, by default it is a ``\verb|*|''\\
%     \verb|incolumn| or \verb|twocolumn| & The separation line would fit in the column \\&(\emph{automatically applied in two-column documents})\\
%     \verb|off| & Hide all the \verb|mindflow| environments
% \end{tabular}
%
% \DescribeEnv{mindflow}
% Then you can use the mindflow environment as
% \begin{verbatim}
%   \begin{mindflow}
%       ...
%   \end{mindflow}
% \end{verbatim}
%
% \section{Some technical details}
%
% \DescribeMacro{\mindflowTextFont}
% \DescribeMacro{\mindflowNumFont}
% The font for texts and line numbers within the \verb|mindflow|
% environments can be specified by redefining \verb|\mindflowTextFont| and
% \verb|\mindflowNumFont|. By default they are defined as:
% \begin{verbatim}
%   \newcommand{\mindflowTextFont}{\normalfont\footnotesize}
%   \newcommand{\mindflowNumFont}{\normalfont\scriptsize\ttfamily}
% \end{verbatim}
% \DescribeMacro{\mindflowLeft}
% \DescribeMacro{\mindflowRight}
% The left and right marker can be changed by redefining
% \verb|\mindflowLeft| and \verb|\mindflowRight|. Both have the default
% value as ``\verb|*|''.
%
% And finally, the color for texts and line numbers within the \verb|mindflow|
% environments are called \verb|mindflowText| and \verb|mindflowNum|,
% respectively. By default, they have the same color as the context, with
% opacity 30\% and 8\%, respectively. 

% \section{An example}
% With option \verb|linenumber, leftmarker, rightmarker| and the following settings:
% \begin{verbatim}
% \colorlet{mindflowText}{blue!50!cyan}
% \colorlet{mindflowNum}{blue!50!cyan}
% \renewcommand{\mindflowTextFont}{\footnotesize\sffamily}
% \renewcommand{\mindflowNumFont}{\footnotesize\sffamily}
% \renewcommand{\mindflowLeft}{\hspace{1em}\(\succ\)}
% \renewcommand{\mindflowRight}{\(\prec\)}
% \end{verbatim}
% One gets:
% \makeatletter
% \@mindflow@leftmarkertrue
% \makeatother
% \colorlet{mindflowText}{blue!50!cyan}
% \colorlet{mindflowNum}{blue!50!cyan}
% \renewcommand{\mindflowTextFont}{\footnotesize\sffamily}
% \renewcommand{\mindflowNumFont}{\footnotesize\sffamily}
% \renewcommand{\mindflowLeft}{\hspace{1em}\(\succ\)}
% \renewcommand{\mindflowRight}{\(\prec\)}
% \begin{mindflow}
%     \blindtext
% \end{mindflow}
%
% \StopEventually{}
%
% \section{Implementation}
% Below is the complete source code of this package.
%
%    \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{%
    family = @mindflow,
    prefix = @mindflow@
}
\DeclareBoolOption[false]{off}           % Turn off mindflow
\DeclareBoolOption[false]{leftmarker}    % Left marker
\DeclareBoolOption[false]{rightmarker}   % Right marker
\DeclareBoolOption[false]{linenumber}    % Line numbers
\DeclareBoolOption[false]{twocolumn}     % Two column
\DeclareBoolOption[false]{incolumn}      % Separation line fits in the column

\ProcessKeyvalOptions*\relax

\if@mindflow@twocolumn
  \@mindflow@incolumntrue
\fi

%%================================
%% Initialization
%%================================
\RequirePackage{lineno}
\RequirePackage{xcolor}

\colorlet{mfSavedColor}{.}
\colorlet{mindflowText}{mfSavedColor!30}
\colorlet{mindflowNum}{mfSavedColor!8}

\newcommand{\mindflowTextFont}{\normalfont\footnotesize}
\newcommand{\mindflowNumFont}{\normalfont\scriptsize\ttfamily}
\newcommand{\mindflowLeft}{*}
\newcommand{\mindflowRight}{*}

%%================================
%% The mindflow environment
%%================================
\newif\ifLNturnsON

\newcommand*{\mfSepLine}{%
  \parskip=0pt
  \LNturnsONfalse%
  \ifLineNumbers\LNturnsONtrue\fi\nolinenumbers%
  \par\noindent\nopagebreak%
  \if@mindflow@incolumn%
    \makebox[\linewidth]{\rule{\linewidth}{0.4pt}}%
  \else%
    \hspace*{-\paperwidth}\makebox[\linewidth]{\rule{4\paperwidth}{0.4pt}}%
  \fi%
  \nopagebreak\par%
  \ifLNturnsON\linenumbers\fi%
}

\newcounter{recordLN}
\newcounter{mfLN}
\setcounter{mfLN}{1}

\if@mindflow@off
  \RequirePackage{verbatim}
  \let\mindflow=\comment
  \let\endmindflow=\endcomment
\else
  \newenvironment{mindflow}
  {%
    \setcounter{recordLN}{\value{linenumber}}
    \setcounter{linenumber}{\value{mfLN}}
    \LNturnsONfalse%
    \ifLineNumbers\LNturnsONtrue\fi\nolinenumbers%
    \mindflowTextFont\color{mindflowText}%
    \mfSepLine%
    \linenumbers%
    \renewcommand\makeLineNumber{%
      \hss\color{mindflowNum}%
      \if@mindflow@linenumber%
        \mindflowNumFont\LineNumber~%
      \fi%
      \if@mindflow@leftmarker%
        \mindflowLeft\hspace{1em}%
      \fi%
      \if@mindflow@rightmarker%
        \rlap{\hskip\textwidth\hspace{1em}\mindflowRight}%
      \fi%
    }%
  }
  {%
    \par%
    \vspace{-.5\baselineskip}\mfSepLine%
    \ifLNturnsON\linenumbers\fi%
    \setcounter{mfLN}{\value{linenumber}}
    \setcounter{linenumber}{\value{recordLN}}
  }
\fi
%    \end{macrocode}
%
% \Finale
\endinput