ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henning Hraban Ramm <hraban@fiee.net>
Subject: Re: Conversion LaTeX -> ConTeXt
Date: Wed, 18 Jun 2003 21:21:46 +0200	[thread overview]
Message-ID: <1A65D657-A1C2-11D7-9ED9-0030659899AA@fiee.net> (raw)
In-Reply-To: <BB15FF87.3BBA%maillist@sonnemans.net>

[-- Attachment #1: Type: text/plain, Size: 603 bytes --]


Am Mittwoch, 18.06.03, um 11:37 Uhr (Europe/Zurich) schrieb Frank 
Sonnemans:

> I am starting to move away from LaTeX to ConTeXt and was wondering if 
> some
> ConTeXt users have written scripts to convert LaTeX documents to 
> ConTeXt
> documents. Or perhaps just partial conversions, for example from a 
> LaTeX
> tabular environment to a ConTeXt table.

Here you are.
But it's *very* basic and not in any way sophisticated.

If you need some more samples of ConTeXt sources (with
layout definition etc.) have a look at my german
tutorial files at:
http://www.fiee.net/texnique/?menu=0-1-1&lang=de


[-- Attachment #2: latex2context.pl --]
[-- Type: application/octet-stream, Size: 3788 bytes --]

#!/usr/bin/perl -w

print "\nThis is LaTeX2ConTeXt. Version 2002-03-13\n";
print "I'll try to convert your LaTeX file for ConTeXt.\n";
print "copyleft Henning Hraban Ramm, http://www.fiee.net/texnique/\n\n";

unless ($ARGV[0]) {die "You must name a file to convert! $!"};
my $LaTeXDatei = $ARGV[0];
unless (-T $LaTeXDatei) {
	print "$LaTeXDatei not found!\n";
	if (-T $LaTeXDatei.'.tex')  { $LaTeXDatei .= ".tex"; }
} # unless
$LaTeXDatei =~ s/\\/\//g;
rename ($LaTeXDatei, $LaTeXDatei.".bak");

open (QUELLE, $LaTeXDatei.".bak") or die "Can't open $LaTeXDatei! $!";

my $ConTeXtDatei = $LaTeXDatei;
open (ZIEL, ">".$ConTeXtDatei) or die "Can't make $ConTeXtDatei! $!";

# Header (should be an extra file)
print ZIEL "% interface=english output=pdftex\n";
print ZIEL "%D this \\ConTeXt\\ file is automatically converted from \\LaTeX.\n";
print ZIEL "\\enableregime[windows]\n";
print ZIEL "\\mainlanguage[de]\n";
print ZIEL "\\setupencoding[default=texnansi]\n";
print ZIEL "\n";

while (<QUELLE>) {
# disable LaTeX header and some other commands
	s§^%!§%%% §;
	s§^(|\s)(\\document)(style|class)§%%% $2$3§g;
	s§^(|\s)(\\usepackage|\\setlength|\\addtolength|\\normalfont)§%%% $2§g;
#	s§^(|\s)(\\addtolength)§%%% $2§g;

	unless (m/^%/) { # if no comment line
# raw convert environments
		s§\\begin{([^{}]*)}§\\start$1 §g;	# \begin{environment} --> \startenvironment
		s§\\end{([^{}]*)}§\\stop$1 §g;	# \end{environment} --> \stopenvironment
		s§\\begingroup§\\bgroup§g;
		s§\\endgroup§\\egroup§g;
		s§\\include(\s*){([^{}<>\[\]]*)}§\\input $2 §g;	# \include{} --> \input

# convert single commands
		s§\\newcommand§\\def§g;	# \newcommand --> \def
		s§\\new(environment)(\s*){([^{}]*)}§\\define$1\[$3\]§g;	# \newenvironment{} --> \defineenvironment[]
		s§\\label§\\reference§g;	# \label --> \reference
		s§\\\\\*§\\\\§g;	# \\* --> \\
		s§\\(big|small)skip§\\blank\[$1\]§g;	# \...skip --> \blank[...]
		s§\"`(.*)\"'§\\quote{$1}§g;
		s§``(.*)''§\\quotation{$1}§g;
		s§\\select(language){([^{}]*)}§\\$1\[$2\]§g;	# \selectlanguage{lang} --> \language[lang]
		s§\\new(page)§\\$1§g;	# \newpage --> \page
		s§\\(|this)pagestyle{empty}§\\setupheaders[state=stop]§g;
		s§\\(|this)pagestyle{([^{}]*)}§\\setupheaders[state=start] \% $2§g;
		s§\\areaset{([^{}]*)}{([^{}]*)}§\\setuplayout[width=$1, height=$2]§g;

#		s§LaTeX§ConTeXt§gi;

# correct environments
		s§\\(start|stop)document§\\$1text§g;
		s§(\\startitemize)§$1\[1\]§g;
		s§\\(start|stop)enumeration§\\$1itemize[n]§g;
		s§\\(start|stop)(verbatim|alltt)§\\$1typing§g;
		s§\\(start|stop)verse§\\$1lines§g;
		s§\\(start|stop)center§\\$1centered§g;
		s§\\(start|stop)tabular(x*)§\\$1tabulate§g;
		s§\\(start|stop)long(table)§\\$1$2§g;
		s§\\(start|stop)multicols(\s*){(0-9)}§\\$1columns[n=$3]§g;
		s§\\twocolumn§\\startcolumns[n=2]§g;
		s§\\onecolumn§\\stopcolumns§g;

# correct titles
		s§(\\part)(\**)§$1§g;	# \part* --> \part
		s§\\chapter\*§\\title§g;
		s§\\(|sub)section\*§\\$1subject§g;
		s§\\paragraph§\\subsubsubsection§g;
#		s§§§g;
#		s§§§g;

# correct tables
		s§(\\starttabulate)(\s*){([^{}]*)}§$1$2\[\|$3\|\]§g;
		s§&§\\NC §g;
		s§\\hline§\\HL§g;
		s§\\(top|bottom|mid)rule§\\HL§g;

# correct typography
		s§\\verb(\||\+)([^\|]*)(\||\+)§\\type{$2}§g;
		s§\\verb§\\type§g;
		s§\\type{\\§\\tex{§g;
		s§\\texttt§\\type§g;
		s§\\emph{§{\\em §g;
		s§\\text(bf|sc|it|sl){§{\\$1 §g;
		s§\\(rm|ss|tt)family§\\switchtobodyfont\[$1\]§g;
		s§\\small §\\tfx §g;
		s§\\Small §\\tfxx §g;
		s§\\large §\\tfa §g;
		s§\\Large §\\tfb §g;
	} # unless comment line
	print ZIEL;
	print ".";
} # while
print "\n";

close (ZIEL);
close (QUELLE);

[-- Attachment #3: Type: text/plain, Size: 61 bytes --]



Grüßlis vom Hraban!
-- 
http://www.fiee.net/texnique/

      reply	other threads:[~2003-06-18 19:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-18  9:37 Frank Sonnemans
2003-06-18 19:21 ` Henning Hraban Ramm [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1A65D657-A1C2-11D7-9ED9-0030659899AA@fiee.net \
    --to=hraban@fiee.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).