summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ulqda/ulqda.sty
blob: 027d7cc32f0af85cc18138c57c3d9a4f21d03d62 (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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
%%
%% This is file `ulqda.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ulqda.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2009 by Ivan Griffin
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.2 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.2 or later is part of all distributions of
%% LaTeX version 1999/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{ulqda}
  [2009/06/11 v1.1 Qualitative Data Analysis package]
\RequirePackage{multicol}
\RequirePackage{tikz}
%%  dot2texi.sty in CTAN doesn't support the cache option yet
%%  The SVN version does.
\RequirePackage{dot2texi}
\usetikzlibrary{backgrounds,shapes,arrows,positioning}


\definecolor[named]{UlQda@lightblue}{rgb}{0.80,0.85,1}
\RequirePackage{soul}
\sethlcolor{UlQda@lightblue}

\newif\ifUlQda@debug \UlQda@debugfalse
\newif\ifUlQda@cache \UlQda@cachefalse
\newif\ifUlQda@cachepresent \UlQda@cachepresentfalse
\newif\ifUlQda@shellescape \UlQda@shellescapetrue
\newif\ifUlQda@MiKTeX \UlQda@MiKTeXfalse
\newif\ifUlQda@active \UlQda@activefalse
\newif\ifUlQda@counts \UlQda@countsfalse

\DeclareOption{active}{\UlQda@activetrue}
\DeclareOption{debug}{\UlQda@debugtrue}
\DeclareOption{cache}{\UlQda@cachetrue}
\DeclareOption{nocache}{\UlQda@cachefalse}
\DeclareOption{shell}{\UlQda@shellescapetrue}
\DeclareOption{noshell}{\UlQda@shellescapefalse}
\DeclareOption{MiKTeX}{\global\UlQda@MiKTeXtrue}
\DeclareOption{counts}{\global\UlQda@countstrue}

\DeclareOption*{%
  \PackageWarning{ulqda}{Unknown option `\CurrentOption'}%
}

\ExecuteOptions{shell}
\ProcessOptions\relax

\ifUlQda@counts
   \def\UlQda@counts{--number }
\else
   \def\UlQda@counts{ }
\fi

%% test if shell escape really works
\ifUlQda@shellescape
  \def\tmpfile{/tmp/shellEscapeTest-\the\year\the\month\the\day-\the\time}
  \immediate\write18{\ifUlQda@MiKTeX rem >"\tmpfile" \else touch \tmpfile \fi}
  \IfFileExists{\tmpfile}{
    \UlQda@shellescapetrue
    \immediate\write18{\ifUlQda@MiKTeX del "\tmpfile" \else rm -f \tmpfile \fi}
  }{\UlQda@shellescapefalse}
\fi

\ifUlQda@shellescape
  \ifUlQda@debug
    \PackageInfo{ulqda}{TeX Shell escape enabled.}
  \fi
\else
  \PackageWarningNoLine{ulqda} {TeX Shell escape not enabled.\MessageBreak%
     Manually process the CSV output with ulqda.pl}
\fi

\newcommand{\ulqdaHighlight}[2]{%
    \hl{\protect\ul{#2}}%
    \marginpar%
    {\raggedright\hbadness=10000\tiny\it%
      \hl{#1}
  \par}%
  %\par%
  }

\newcommand{\ulQda}{\textsf{ul\kern -.075em\lower .3ex\hbox {\protect\emph{q}}da}}

\ifUlQda@active
  \AtBeginDocument{%
    \typeout{ulqda: Loaded - 2009/06/11 v1.1 Qualitative Data Analysis package}
    \ifUlQda@cache
      \IfFileExists{\jobname.csv} %
      {
        \ifUlQda@debug
          \typeout{ulqda: QDA cache file \jobname.csv found}
        \fi
        \UlQda@cachepresenttrue
      }
      {
        \ifUlQda@debug
          \typeout{ulqda: QDA cache file \jobname.csv not found}
        \fi
        \UlQda@cachepresentfalse
      }
    \else
      \ifUlQda@debug
        \typeout{ulqda: caching disabled}
      \fi
      \UlQda@cachepresentfalse
    \fi

  % Code macro
    \ifUlQda@cachepresent
      \newcommand{\ulqdaCode}[2]{\ulqdaHighlight{#1}{#2}}
    \else
      \ifUlQda@debug
        \typeout{ulqda: Creating QDA cache file \jobname.csv} %
      \fi
      \newwrite\ulqdaCodeFile %
      \immediate\openout\ulqdaCodeFile=\jobname.csv %
      \immediate\write\ulqdaCodeFile{Page Number, Section, Code, Text} %

      \def\UlQda@ListIt#1[#2,{%
        \ifUlQda@debug %
          \typeout{ulqda: Coding "#2" as "#1" on page \thepage, section \thesection}
        \fi %
        \immediate\write\ulqdaCodeFile{\thepage, \thesection, #2, "#1"}
        \index{#2} %
        \@ifnextchar]%             Look ahead one token.
          {\eatthesquarebracket}%  End of list.
          {\UlQda@ListIt{#1}[}%     Process rest of list.
      }
      \def\eatthesquarebracket]{}  % Gobble the square bracket.
      %
      % Coding macro
      \newcommand{\ulqdaCode}[2]{\ulqdaHighlight{#1}{#2}\UlQda@ListIt{#2}[#1,]} %
    \fi
  } % end of \AtBeginDocument

\newcommand{\UlQda@FirstOfTwo}[1]{
  \ifx#1\UlQda@MyUndefinedMacro
    ?\typeout{ulqda: undefined reference, please re-run}
  \else
    \expandafter\@firstoftwo#1
  \fi}
\newcommand{\UlQda@RefToSectNum}[1]{
  \expandafter \ifx\csname r@#1\endcsname\relax
    ?\typeout{ulqda: undefined reference, please re-run}
  \else
    \expandafter\UlQda@FirstOfTwo\csname r@#1\endcsname
  \fi}
  \def\UlQda@filter{}
  \newcommand{\ulqdaSetSectFilter}[1]{
      \ifUlQda@shellescape
        \immediate\write18{\ifUlQda@MiKTeX del \else rm -f -- \fi \jobname_net.dot}
        \immediate\write18{\ifUlQda@MiKTeX del \else rm -f -- \fi \jobname_flat.dot}
        \immediate\write18{\ifUlQda@MiKTeX del \else rm -f -- \fi \jobname_table.tex}
      \fi
      \def\UlQda@filter{--filter \UlQda@RefToSectNum{#1}}
  }
  \newcommand{\ulqdaClearSectFilter}{\def\UlQda@filter{}}
  \newcommand{\ulqdaGraph}[2]{\expandafter\csname UlQda@Graph#1\endcsname{#2}}
  \newcommand\UlQda@Graphflat[1]{\UlQda@GraphFlat{#1}}
  \newcommand\UlQda@Graphnet[1]{\UlQda@GraphNet{#1}}
  \newcommand{\UlQda@GraphVizFileName}{}
  \newsavebox{\UlQda@GraphSaveBox}
  \newcommand{\UlQda@GraphNet}[1]{%
    \renewcommand{\UlQda@GraphVizFileName}{\jobname_net.dot}%
    \ifUlQda@cachepresent
      \ifUlQda@shellescape
        \ifUlQda@debug
          \typeout{ulqda: Converting .csv to hierarchical GraphViz dot file}
        \fi
        \immediate\write18{ulqda.pl --graphnet \UlQda@filter \UlQda@counts
                             -- \jobname.csv \jobname_net.dot}
      \fi
    \fi

    \UlQda@DoGraph{#1}%
  }
  \newcommand{\UlQda@GraphFlat}[1]{%
    \renewcommand{\UlQda@GraphVizFileName}{\jobname_flat.dot}%
    \ifUlQda@cachepresent
      \ifUlQda@shellescape
        \ifUlQda@debug
          \typeout{ulqda: Converting .csv to flat GraphViz dot file}
        \fi
        \immediate\write18{ulqda.pl --graphflat \UlQda@filter \UlQda@counts
                             -- \jobname.csv \jobname_flat.dot}
      \fi
    \fi

    \UlQda@DoGraph{#1}%
  }

  \newcommand{\UlQda@DoGraph}[1]{
    \IfFileExists{\UlQda@GraphVizFileName}{
      \ifUlQda@shellescape
        \begin{lrbox}{\UlQda@GraphSaveBox}
          \stepcounter{dtt@fignum}
          \setkeys{dtt}{#1}
          \immediate\write18{cp "\UlQda@GraphVizFileName" "\dtt@figname.dot"}
          \dottotexgraphicsinclude
        \end{lrbox}
        \framebox{\usebox{\UlQda@GraphSaveBox}} \par
      \else
        \typeout{ulqda: shell escape not enabled}
        \typeout{ulqda: unable to process \UlQda@GraphVizFileName}
      \fi
    }
  }
  \newcommand{\ulqdaTable}{
    \IfFileExists{\jobname_table.tex}{
      \input{\jobname_table.tex}
    }{
      \ifUlQda@cachepresent
        \ifUlQda@shellescape
          \ifUlQda@debug
            \typeout{ulqda: Converting .csv to TeX table}
          \fi
          \immediate\write18{ulqda.pl --list \UlQda@filter \UlQda@counts
                               -- \jobname.csv \jobname_table.tex}
        \fi
      \fi
      \IfFileExists{\jobname_table.tex}{
        \input{\jobname_table.tex}
      }
    }
  }
  \newcommand{\ulqdaCloud}{
    \IfFileExists{\jobname_cloud.tex}{
      \input{\jobname_cloud.tex}
    }{
      \ifUlQda@cachepresent
        \ifUlQda@shellescape
          \ifUlQda@debug
            \typeout{ulqda: Converting .csv to TeX cloud}
          \fi
          \immediate\write18{ulqda.pl --cloud \UlQda@filter \UlQda@counts
                               -- \jobname.csv \jobname_cloud.tex}
        \fi
      \fi
      \IfFileExists{\jobname_cloud.tex}{
        \input{\jobname_cloud.tex}
      }
    }
  }
\else % UlQda@activefalse
  \newcommand{\ulqdaTable}{}
  \newcommand{\ulqdaCloud}{}
  \newcommand{\ulqdaGraph}[2]{}
  \newcommand{\ulqdaCode}[2]{#2}
  \newcommand{\ulqdaSetSectFilter}[1]{}
  \newcommand{\ulqdaClearSectFilter}{}
\fi
\endinput
%%
%% End of file `ulqda.sty'.