Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'iansecs.sty')
-rw-r--r--iansecs.sty109
1 files changed, 74 insertions, 35 deletions
diff --git a/iansecs.sty b/iansecs.sty
index 5385df6..5e0408e 100644
--- a/iansecs.sty
+++ b/iansecs.sty
@@ -34,24 +34,40 @@
%% style for the equation number
\def\eqnumstyle{}
+%% hyperlinks
+% hyperlinkcounter
+\newcounter{lncount}
+% hyperref anchor
+\def\hrefanchor{%
+\stepcounter{lncount}%
+\hypertarget{ln.\thelncount}{}%
+}
%% define a command and write it to aux file
\def\outdef#1#2{%
% define command
-\expandafter\xdef\csname #1\endcsname{\noexpand\hyperlink{page.\the\count0}{#2}}%
-% write command to aux
-\immediate\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname #1\endcsname{\noexpand\hyperlink{page.\thepage}{#2}}}%
-% define ref with no link
-\expandafter\xdef\csname #1@nol\endcsname{#2}%
+\expandafter\xdef\csname #1\endcsname{#2}%
+% hyperlink number
+\expandafter\xdef\csname #1@hl\endcsname{\thelncount}%
% write command to aux
-\immediate\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname #1@nol\endcsname{#2}}%
+\immediate\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname #1\endcsname{\csname #1\endcsname}}%
+\immediate\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname #1@hl\endcsname{\thelncount}}%
}
+
%% define a label for the latest tag
%% label defines a command containing the string stored in \tag
\AtBeginDocument{
\def\label#1{\expandafter\outdef{#1}{\safe\tag}}
- \def\ref#1{\expandafter\safe\csname #1\endcsname}
+
+\def\ref#1{%
+% check whether the label is defined (hyperlink runs into errors if this check is ommitted)
+\ifcsname #1@hl\endcsname%
+\hyperlink{ln.\csname #1@hl\endcsname}{\safe\csname #1\endcsname}%
+\else%
+\safe\csname #1\endcsname%
+\fi%
+}
}
%% counters
@@ -71,7 +87,7 @@
\newlength\sectitlewidth
\def\section#1{%
% reset counters
-\refstepcounter{sectioncount}%
+\stepcounter{sectioncount}%
\setcounter{subsectioncount}{0}%
\setcounter{pointcount}{0}%
\setcounter{subpointcount}{0}%
@@ -82,7 +98,12 @@
% space before section (if not first)
\ifnum\thesectioncount>1%
\seqskip%
+\penalty-1000%
\fi%
+% hyperref anchor
+\hrefanchor%
+% define tag (for \label)
+\xdef\tag{\sectionprefix\thesectioncount}%
% get widths
\def\@secnum{{\bf\Large\sectionprefix\thesectioncount.\hskip10pt}}%
\settowidth\secnumwidth{\@secnum}%
@@ -91,21 +112,21 @@
% print name
\parbox{\textwidth}{%
\@secnum%
-\parbox[t]{\sectitlewidth}{\Large\bf #1}%
-\par\penalty10000%
-\bigskip}\par\penalty10000%
-% define tag (for \label)
-\xdef\tag{\sectionprefix\thesectioncount}%
+\parbox[t]{\sectitlewidth}{\Large\bf #1}}%
% write to table of contents
\iftoc%
+% save lncount in aux variable which is written to toc
+\immediate\write\tocoutput{\noexpand\expandafter\noexpand\edef\noexpand\csname toc@sec.\thesectioncount\endcsname{\thelncount}}%
\write\tocoutput{\noexpand\tocsection{#1}{\thepage}}%
\fi%
+\par\penalty10000%
+\bigskip\penalty10000%
}
%% subsection
\def\subsection#1{
% counters
-\refstepcounter{subsectioncount}%
+\stepcounter{subsectioncount}%
\setcounter{pointcount}{0}%
\setcounter{subpointcount}{0}%
\setcounter{subsubpointcount}{0}%
@@ -115,7 +136,12 @@
% space before subsection (if not first)
\ifnum\thesubsectioncount>1%
\subseqskip%
+\penalty-500%
\fi%
+% hyperref anchor
+\hrefanchor
+% define tag (for \label)
+\xdef\tag{\sectionprefix\thesectioncount.\thesubsectioncount}%
% get widths
\def\@secnum{{\bf\large\hskip.5cm\sectionprefix\thesectioncount.\thesubsectioncount.\hskip5pt}}%
\settowidth\secnumwidth{\@secnum}%
@@ -124,34 +150,40 @@
% print name
\parbox{\textwidth}{%
\@secnum%
-\parbox[t]{\sectitlewidth}{\large\bf #1}%
-\par\penalty10000%
-\medskip}\par\penalty10000%
-% define tag (for \label)
-\xdef\tag{\sectionprefix\thesectioncount.\thesubsectioncount}%
+\parbox[t]{\sectitlewidth}{\large\bf #1}}%
% write to table of contents
\iftoc%
-\write\tocoutput{\noexpand\tocsubsection{#1}{\the\count0}}%
+% save lncount in aux variable which is written to toc
+\immediate\write\tocoutput{\noexpand\expandafter\noexpand\edef\noexpand\csname toc@subsec.\thesectioncount.\thesubsectioncount\endcsname{\thelncount}}%
+\write\tocoutput{\noexpand\tocsubsection{#1}{\thepage}}%
\fi%
+\par\penalty10000%
+\medskip\penalty10000%
}
%% points
\def\point{
- \refstepcounter{pointcount}
+ \stepcounter{pointcount}
\setcounter{subpointcount}{0}
+ % hyperref anchor
+ \hrefanchor
\indent{\bf \thepointcount\ - }
% define tag (for \label)
\xdef\tag{\thepointcount}
}
\def\subpoint{
- \refstepcounter{subpointcount}
+ \stepcounter{subpointcount}
\setcounter{subsubpointcount}0
+ % hyperref anchor
+ \hrefanchor
\indent\hskip.5cm{\bf \thepointcount-\thesubpointcount\ - }
% define tag (for \label)
\xdef\tag{\thepointcount-\thesubpointcount}
}
\def\subsubpoint{
- \refstepcounter{subsubpointcount}
+ \stepcounter{subsubpointcount}
+ % hyperref anchor
+ \hrefanchor
\indent\hskip1cm{\bf \thepointcount-\thesubpointcount-\thesubsubpointcount\ - }
% define tag (for \label)
\xdef\tag{\thepointcount-\thesubpointcount-\thesubsubpointcount}
@@ -165,7 +197,7 @@
%% equation numbering
\def\seqcount{
- \refstepcounter{seqcount}
+ \stepcounter{seqcount}
% the output
\edef\seqformat{\theseqcount}
% add subsection number
@@ -184,7 +216,7 @@
\marginnote{\eqnumstyle\hfill(\seqformat)}
}
%% equation environment compatibility
-\def\equation{$$\seqcount}
+\def\equation{\hrefanchor$$\seqcount}
\def\endequation{$$\@ignoretrue}
%% figures
@@ -193,7 +225,9 @@
\addtolength\figwidth{-2.5cm}
\def\figcount#1{%
-\refstepcounter{figcount}%
+\stepcounter{figcount}%
+% hyperref anchor
+\hrefanchor%
% the number of the figure
\edef\figformat{\thefigcount}%
% add section number
@@ -210,10 +244,10 @@
%% environment
\def\figure{
- \vfill\hbox{}
+ \par\penalty-500
}
\def\endfigure{
- \vfill\hbox{}
+ \par\penalty-1000
}
\let\caption\figcount
@@ -224,9 +258,11 @@
%% theorem headers
\def\theo#1{
- \refstepcounter{Theocount}
+ \stepcounter{Theocount}
% reset points
\ifresetpointattheo\resetpointcounter\fi
+ % hyperref anchor
+ \hrefanchor
% the number
\def\formattheo{\theTheocount}
% add section number
@@ -253,7 +289,7 @@
{\bf \LARGE Appendices}\par\penalty10000\bigskip\penalty10000%
% add a mention in the table of contents
\iftoc%
-\write\tocoutput{\noexpand\tocappendices}\penalty10000%
+\immediate\write\tocoutput{\noexpand\tocappendices}\penalty10000%
\fi%
%% uncomment for new page for each appendix
%\def\seqskip{\vfill\pagebreak}
@@ -261,11 +297,14 @@
%% start references
\def\references{%
+\hrefanchor%
% write
{\bf \LARGE References}\par\penalty10000\bigskip\penalty10000%
% add a mention in the table of contents
\iftoc%
-\write\tocoutput{\noexpand\tocreferences{\the\count0}}\penalty10000%
+% save lncount in aux variable which is written to toc
+\immediate\write\tocoutput{\noexpand\expandafter\noexpand\edef\noexpand\csname toc@references\endcsname{\thelncount}}%
+\write\tocoutput{\noexpand\tocreferences{\thepage}}\penalty10000%
\fi%
}
@@ -301,12 +340,12 @@
\stepcounter{tocsectioncount}
\setcounter{tocsubsectioncount}{0}
% write
- \smallskip\hyperlink{page.#2}{{\bf \tocsectionprefix\thetocsectioncount}.\hskip5pt #1\leaderfill#2}\par
+ \smallskip\hyperlink{ln.\csname toc@sec.\thetocsectioncount\endcsname}{{\bf \tocsectionprefix\thetocsectioncount}.\hskip5pt #1\leaderfill#2}\par
}
-\def\tocsubsection #1#2{
+\def\tocsubsection #1#2#3{
\stepcounter{tocsubsectioncount}
% write
- {\hskip10pt\hyperlink{page.#2}{{\bf \thetocsubsectioncount}.\hskip5pt {\small #1}\leaderfill#2}}\par
+ {\hskip10pt\hyperlink{ln.\csname toc@subsec.\thetocsectioncount.\thetocsubsectioncount\endcsname}{{\bf \thetocsubsectioncount}.\hskip5pt {\small #1}\leaderfill#3}}\par
}
\def\tocappendices{
\medskip
@@ -317,6 +356,6 @@
}
\def\tocreferences#1{
\medskip
- {\hyperlink{page.#1}{{\bf References}\leaderfill#1}}\par
+ {\hyperlink{ln.\csname toc@references\endcsname}{{\bf References}\leaderfill#1}}\par
\smallskip
}