\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#256: Implement Tabular and Wordprocessor Style Tabbing}
\date{August 12, 2005}
\author{Vince Darley, Vince Darley}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#256}&\textbf{Implement Tabular and Wordprocessor Style Tabbing}\\\hline
Author&

Vince Darley \tipmail{vince}{santafe.edu}
\par
Vince Darley \tipmail{vincentdarley}{users.sourceforge.net}
\\
Created&Friday, \(\text{12}^{\text{th}}\) August 2005\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.15 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

There are two common style of tabbing in the computer world: that used for a regular table of information, and that used by a word-processor/text editor. This TIP proposes to add support for the latter to Tk's \textbf{text} widget.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Overview}

Tk's \textbf{text} widget has historically only supported a \textit{tabular} style of tabbing, where the n'th tab character is associated explicitly with the n'th tab stop (irrespective of whether that stop is to the left or right of the current x-position --- if that stop is to the left then a single space is inserted as a fallback). A \textit{wordprocessor} (or typewriter) has a different style in which a tab character is associated with the next tab stop to the right of the current x-position.

This TIP proposes to add wordprocessor-style tabbing to Tk's \textbf{text} widget.

Tk 8.4 only supports tabular tabbing (except for the special \textit{-tabs \{\}} case, which uses wordprocessor style 8-tabs!), although none of this is clearly documented at all. Tk 8.5 at present actually only supports wordprocessor style tabbing (and fixed a bunch of other bugs present in Tk 8.4's tab handling). This behaviour change was an inadvertent result of fixing bugs in the code without the correct behaviour being very clearly specified. Hence this TIP will restore the old behaviour (minus bugs) as the default, and add the option of the new wordprocessor style behaviour.

\section{Proposal}

A new \textbf{-tabstyle} configuration option will be added to the \textbf{text} widget, taking the values \textbf{wordprocessor} or \textbf{tabular} to specify the style of tabbing. The same option will also be added to \textbf{tags} in the text widget (which, as usual, will also allow an empty value for the configuration option). The default style of tabbing will be \textbf{tabular} for compatibility with Tk 8.4. Neither style name may be abbreviated.

As a result of this change, abbreviations such as \textbf{-ta} or \textbf{-tab} will become ambiguous and trigger an error. This is considered a bug in the calling script (and a trivial thing to fix in such scripts). Similar ambiguities have been introduced by TIPs in the past (e.g. with \textit{grid}). It may actually be a useful ambiguity, in that it will alert script writers to the fact that new tabbing functionality is available, and in particular that a decision on desired tab style needs to be made.

In addition the strange difference in Tk 8.4 between an empty \textbf{-tabs} value and any other value will be changed for Tk 8.5 --- it will use the \textbf{-tabstyle} option to determine how to interpret tabs under all circumstances, and use the \textbf{-tabs} list simply to determine the location of the tab stops.

Here's an example usage:
\begingroup\small\begin{verbatim}
pack [text .t]
.t configure -tabs {0.5i 1.0i 1.5i 2.0i 2.5i 3.0i 3.5i 4.0i 4.5i}
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t insert end "a\tb\tc\tasdbcanasdasd\te\tf\tg\n"
.t tag configure wordprocessor -tabstyle wordprocessor
.t tag add wordprocessor 3.0 5.0
.t tag configure tabular -tabstyle tabular
.t tag add tabular 5.0 7.0
\end{verbatim}
\endgroup

and here's an example showing how Tk 8.4 does \textit{not} move you to the next tab stop to the right each time:
\begingroup\small\begin{verbatim}
pack [text .t]
.t configure -tabs {0.25i}
.t insert end "[string repeat a 20][string repeat \tb 10]"
\end{verbatim}
\endgroup

The above behaves completely differently in Tk 8.4 and 8.5 at present.

\section{Implementation}

A full implementation, with documentation and tests is available at SourceForge [\url{http://sf.net/tracker/?func=detail&aid=1247835&group_id=12997&atid=112997}]. The bug report also contains some further discussion on this issue.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
