summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/dlfltxb/dlfltxbmisc.sty
blob: 5788d06adbf794154f6cb745473fee3fb16fce0c (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
\ProvidesPackage{dlfltxbmisc}[2010/03/04 v0.3 by Lars Madsen]

% This package 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 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Lars Madsen (daleif@imf.au.dk).
%%



% if memoir is not loaded we will need the chngpage to get adjustwidth
\@ifclassloaded{memoir}{}{
  \RequirePackage{chngpage}
}

\RequirePackage{ragged2e}
\RequirePackage{url}
\RequirePackage{calc}

\@ifundefined{marg}{\newcommand\marg{}}{}
\@ifundefined{oarg}{\newcommand\oarg{}}{}
\@ifundefined{parg}{\newcommand\parg{}}{}


\newcommand*\Arg@s[1]{\textnormal{\texttt{#1}}}%
\newcommand*\Arg@n[1]{\textnormal{$\langle$\textit{#1}$\rangle$}}%
\newcommand*\Arg{\@ifstar{\Arg@s}{\Arg@n}}%

\newcommand*\marg@s[1]{\textnormal{\texttt{\{#1\}}}}
\newcommand*\marg@n[1]{%
  \textnormal{\texttt{\{}$\langle$\textit{#1}$\rangle$\texttt{\}}}%
}
\renewcommand*\marg{\@ifstar{\marg@s}{\marg@n}}

\newcommand*\oarg@s[1]{\textnormal{\texttt{[#1]}}}
\newcommand*\oarg@n[1]{%
  \textnormal{\texttt{[}$\langle$\textit{#1}$\rangle$\texttt{]}}%
}
\renewcommand*\oarg{\@ifstar{\oarg@s}{\oarg@n}}

\newcommand*\parg@s[1]{\textnormal{\texttt{(#1)}}}
\newcommand*\parg@n[1]{%
  \textnormal{\texttt{(}$\langle$\textit{#1}$\rangle$\texttt{)}}%
}
\renewcommand*\parg{\@ifstar{\parg@s}{\parg@n}}

\newcommand\malign[2][2pt]{%
  \makebox[0pt][l]{\kern#1\smash{\rule[-1.5mm-#2\baselineskip]{0.01pt}{5mm+#2\baselineskip}}}%
}


\newenvironment{syntax}{%
  \vskip.5\baselineskip\allowbreak%
  \begin{adjustwidth}{\parindent}{0pt}
    \parindent=0pt%
    \obeylines%
    \let\\=\relax%
  }{%
  \end{adjustwidth}%
  \vskip.5\baselineskip%
}
\newenvironment{syntax*}{%
  \vskip.5\baselineskip%
  \begin{adjustwidth}{\parindent}{0pt}
    \parindent=0pt%
  }{%
  \end{adjustwidth}%
  \vskip.5\baselineskip%
}

\let\syntaks=\syntax
\let\endsyntaks=\endsyntax

% macro used in several math examples to show the structure. It acts
% like some text but only displays a box.
\newcommand\@dbx[1]{{\fboxsep=0pt\fboxrule=0.4pt\,\fbox{\phantom{\rule[-0.6mm]{#1}{3mm}}}\,}}
\newcommand\dbx[1][5mm]{\ifmmode\mathord{\@dbx{#1}}\else\@dbx{#1}\fi}


% powerfull macro by Morten H\o gholm, this enables you to measure the
% length of the previous paragraf.
\newdimen\lastlinedim
\def\getlastlinesize{%
   \begingroup\frozen@everydisplay{}%
        $$
        \abovedisplayskip=\z@skip \abovedisplayshortskip=\z@skip
        \belowdisplayskip=\z@skip \belowdisplayshortskip=\z@skip
        \global\lastlinedim=\dimexpr\predisplaysize-2em\relax
        \halign{##\cr}%
        $$
        \mbox{}%
        \endgroup%
}

% this is a very special little macro to be used in the 'note' field
% of bibtex entries. It eats up the added '.' and typesets the main
% argument (an URL) in a raggedright manner, wrapped up into the
% previous paragraph. It looks pretty cool.
\newcommand\addurl[3][\textsf{URL}:]{%
  \getlastlinesize{}%
  \vskip-2\baselineskip%
  \begingroup%
  \urlstyle{sf}
  \def\UrlNoBreaks{\do\(\do\[\do\{\do\<\do\:\do\.}%\]
  \RaggedLeft%
  \fussy%
  \hbadness=10000% cheating
  \addtolength\lastlinedim{-\bibhang}%
  \fboxsep=0pt%
  \fboxrule=0pt%
  \fbox{\hbox to \lastlinedim{\hfill \footnotesize \strut   \hfill}}%
  \ifdim \lastlinedim > 0.6\linewidth\relax% we break
  \nopagebreak\vskip-3pt%
  \else%
  % special thanks to Dan Luecking for this, since my original
  % \hspace{\fill} failed miserably
  \hskip1em plus 5em minus .7em
  \fi%
  {\footnotesize #1~~{\url{#2}}} % 
  \par%
  \endgroup%
}

\AtBeginDocument{\providecommand\href[2]{#2}}

\DeclareUrlCommand\mypath{\urlstyle{sf}}
%\urlstyle{rm}
\newcommand\addCTAN[3][\textsf{CTAN}:]{%
  \getlastlinesize{}%
  \vskip-2\baselineskip%
  \begingroup%
%  \urlstyle{rm}
  \def\UrlNoBreaks{\do\(\do\[\do\{\do\<\do\:\do\.}%\]
  \RaggedLeft%
  \fussy%
  \hbadness=10000% cheating
  \addtolength\lastlinedim{-\bibhang}%
  \fboxsep=0pt%
  \fboxrule=0pt%
  \fbox{\hbox to \lastlinedim{\hfill \footnotesize \strut   \hfill}}%
  \ifdim \lastlinedim > 0.6\linewidth\relax% we break
  \nopagebreak\vskip-3pt%
  \else%
  % special thanks to Dan Luecking for this, since my original
  % \hspace{\fill} failed miserably
  \hskip1em plus 5em minus .7em
  \fi%
  {\footnotesize
    \href{http://mirror.ctan.org/#2}{#1~~{\mypath{#2}}}} % 
  \par%
  \endgroup%
}

\newcommand\CTAN[1]{%
  {\footnotesize\href{http://mirror.ctan.org/#1}{\textsf{CTAN:}~{\mypath{#1}}}}}