Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tab aware macros

1 view
Skip to first unread message

Yogi

unread,
Nov 19, 2009, 6:18:37 PM11/19/09
to yogeshw...@gmail.com
Hi there,

I have been trying for a long times to write a macro that uses the
information about the indentation of line in the tex file. May be this
is completely against the TeX-philosophy, but here is what I want to
do:

I want to write something like

\heading First level heading
\heading Second level heading
\heading Third level heading

(Note: there are some tabs before second and third lines.) I want to
automatically convert first line to \section{#1}, the second line to
\subsection{#1}, and so on (or something similar). It will be even
cooler if I did not have to use the macro \heading in the beginning.
May be I can just write some infrequently used character, like .
(dot), since dot is almost never used at the beginning of the line.
So, these lines will become:

. First level heading
. Second level heading
. Third level heading

You ask why? I am trying to write some quick outlining package in
LaTeX, and it helps to quickly jot down one's thought, rather than
worry about writing backslashes and braces.

I have made some progress in the sense that I can write a macro in
which the argument can be delimited by a newline (ref: TeX by Topic
book, around page 122), so I don't have to write { and } around the
arguments (notice that I wrote "\heading First level", and not
"\heading{First level}"). But the question of how to use the
indentation of the line in a macro still eludes me.

I will greatly appreciate any help.

Thanks,
Yogi

Donald Arseneau

unread,
Nov 19, 2009, 11:07:43 PM11/19/09
to
On Nov 19, 3:18 pm, Yogi <yogeshwersha...@gmail.com> wrote:

> I have been trying for a long times to write a macro that uses the
> information about the indentation of line in the tex file.

> I want to write something like

> . First level heading


> . Second level heading
> . Third level heading

I had been working on a system to format text based on this
type of cue way back. The intention was to have package
documentation typeset but still well formatted in its plain text
form (not like the horror of dtx). Unfortunately, the macros
disappeared and have not shown up again.

First, do you really mean tab characters, or a sequence of
spaces?

You will have to operate with \obeylines and \obeyspaces in
effect and have the macro for ^^M look for the following
spaces (or tabs). If \obeyspaces is a problem, you can have
^^M declare it temporarily just while looking for the spaces.

If you are willing to put a blank line before the titles (as you
should do) then you don't need to make any characters
permanently active -- just define \par.

\newcount\numspaces
\def\par{\endgraf \begingroup\obeyspaces
\numspaces=0\relax
\countspaces\relax}
\def\countspaces#1{%
\futurelet\nextchar\lookforspace}
\def\lookforspace{%
\ifx\nextchar\space
\advance\numspaces 1\relax
\expandafter\countspaces
\else
% do various things depending on \numspaces and \nextchar
\endgroup % end effect of \obeyspaces
\fi
}

I would use a lead-in character of "." and "o" and "-" for different
levels of nesting, and would use "_" (like underlining) as an
indicator
of sectioning titles, like the following:

_Title Level One_

_Title level two_


Donald Arseneau


Will Robertson

unread,
Nov 20, 2009, 1:42:58 AM11/20/09
to
On 2009-11-20 14:37:43 +1030, Donald Arseneau <as...@triumf.ca> said:

> The intention was to have package
> documentation typeset but still well formatted in its plain text
> form (not like the horror of dtx).

Now this certainly explains some things :)

Will

Joseph Wright

unread,
Nov 20, 2009, 1:53:22 AM11/20/09
to

You can imagine a solution where you make tab active. This could then be
used to increment a counter, which would be used by the \header macro to
determine the current indentation level. However, this looks very risky
to me: this will apply to any tabs, and not just those at the start of a
line. I think your much better off looking at pre-processing your file
with some other system rather than trying to do this in TeX.
--
Joseph Wright

Guenter Milde

unread,
Nov 20, 2009, 4:27:03 AM11/20/09
to
On 2009-11-20, Donald Arseneau wrote:
> On Nov 19, 3:18 pm, Yogi <yogeshwersha...@gmail.com> wrote:

>> I have been trying for a long times to write a macro that uses the
>> information about the indentation of line in the tex file.
>> I want to write something like

>> . First level heading
>> . Second level heading
>> . Third level heading

You might consider one of the many existing "ASCII-markup languages".
My personal choice is Docutils' reStructuredText: nice to read and
with tools to export to HTML, LaTeX, odf, manpages, ...
(http://docutils.sf.net/)

...

> The intention was to have package documentation typeset but still well
> formatted in its plain text form (not like the horror of dtx).

PyLit (http://pylit.berlios.de) achieves this combining
reStructuredText with a "dual source" concept. See the isomath package
at CTAN for an example.

Günter Milde

Dan Luecking

unread,
Nov 20, 2009, 1:29:26 PM11/20/09
to
On Fri, 20 Nov 2009 06:53:22 +0000, Joseph Wright
<joseph...@morningstar2.co.uk> wrote:

>Yogi wrote:
>> I want to write something like
>>
>> \heading First level heading
>> \heading Second level heading
>> \heading Third level heading
>>
>> (Note: there are some tabs before second and third lines.) I want to
>> automatically convert first line to \section{#1}, the second line to
>> \subsection{#1}, and so on (or something similar). It will be even
>> cooler if I did not have to use the macro \heading in the beginning.
>> May be I can just write some infrequently used character, like .
>> (dot), since dot is almost never used at the beginning of the line.
>> So, these lines will become:
>>
>> . First level heading
>> . Second level heading
>> . Third level heading
>>
>> You ask why? I am trying to write some quick outlining package in
>> LaTeX, and it helps to quickly jot down one's thought, rather than
>> worry about writing backslashes and braces.
>>

>You can imagine a solution where you make tab active. This could then be
>used to increment a counter, which would be used by the \header macro to
>determine the current indentation level. However, this looks very risky
>to me: this will apply to any tabs, and not just those at the start of a
>line. I think your much better off looking at pre-processing your file
>with some other system rather than trying to do this in TeX.

The AMS used to have a set of macros that allowed one to
typeset the ascii files one used to be get from an electronic
search of Math Reviews. Since each line of a record (apart
from those in the reviewer's text) started with a two-letter
code, these macros made ^^M active, and defined it to examine
the start of the next line for guidance.

One would need tab characters to have some category other than 10
and after ^^M processed those at the start of the line, it would
have to put them back to some reasonably normal state. Details
are an exercise for the student.


Dan
To reply by email, change LookInSig to luecking

0 new messages