3

I would like to create my own LaTeX-derivative markup language. (I asked similar questions before, but this is more limited.) Advice would be useful.

First Question:

I believe there are three main categories of macros between the begin-document and end-document (which I will call the "main document"):

  1. markup (e.g., \textit, \begin{quote})

  2. characters (e.g., \kappa, \Bbb{A})

  3. programming (e.g., \newcommand, \let, \newtheorem).

Is this classification reasonable, or am I omitting a logical class of macros?

I believe everything that can be typeset in LaTeX can still be typeset if I removed #3 from the main document and banned it into the preamble. This means that once my preamble is read, the set of allowed macro names will be fixed, and I just have true markup in my document. Another program could then, in principle, interpret markup (and interpret it differently) without having to be itself TeX.

Second Question:

Is there a long-cut to { } environments? This is when used by itself, not when used to delineate arguments of macros. I mean hello {\it there} as opposed to hello \textit{there}. I am wondering if I can "ban" the plain environment use of the parens in my document, and rely on styling instead. In rare cases where needed, I would then say \begin{env} ... \end{env}. But I have not run into such a situation.

Third question:

Is it possible to change catcodes in the main document, but as soon as LaTeX expands (enters = runs) a macro, the standard catcode definitions hold again? (I.e., so that I can still run all macros that were defined in packages without me having to make changes).

If this is the case, then I could define my own LaTeX dialect. My documents would have the power of standard LaTeX in the preamble, and then

\usepackage[version=2]{newdocument}
\begin{newdocument}
   modified catcodes, outside markup
\end{newdocument}

where the newdocument would be my own version. as for me, I would want

  • | becomes my cell separator in tabulars

  • & become the entity operator, just as in html, i.e., κ and &hashmark;

  • \\ be replaced with something like \nl

  • $ be freed up (i.e., no longer a catcode). my users would have to use \m{...} for math expressions.

  • % be freed up (i.e., no longer be a special catcode). 15% is now what it should be.

Less important:

  • # become the remark operator. without programming, no longer needed otherwise

  • \# be banned in exchange for &hashmark;

Now, processing the input text is easy with Lua or Perl or..., but I would like the documents to remain portable, so this would have to be a standard LaTeX package written in TeX. (If this is easy, I will want to hire someone to implement this. If this is hard, then it's a no go.)

/iaw

4
  • 1
    Modest changes? ;-) You can ban \it, just remove its definition; but you can't really ban users to type {\itshape world} if they want. You can't also avoid them using \newcommand mid document: undefining it would break umpteen packages.
    – egreg
    Feb 12, 2014 at 17:11
  • 1
    Everything you describe is pretty straightforward. For an example of what can be done, the xmltex package lets you insert xml into a TeX file and typeset the <div>...</div> and other things correctly. Feb 12, 2014 at 17:13
  • (old question but) Regarding question 2, note that some macro uses explicit {} to start/end group in its argument, so be careful. You'd need to check where the token comes from before executing it, so best way is to patch TeX the engine, I guess.
    – user202729
    Jul 23, 2022 at 14:31
  • (some time later) I guess it's possible to do \tracingcommands=1 \tracinggroups=1, then replace every {} that appears in your code with corresponding tokens with special char code, then grep the log for {begin-group character x} followed by {entering simple group...} -- note that package code might enter simple group and you usually don't want to prohibit them; but then most nice packages will use semi-simple group instead)
    – user202729
    Aug 4, 2022 at 17:03

1 Answer 1

2

The answer to question 3 is yes. You can see this e.g. for @: its catcode in a document is other but \section has no problem to call the internal \@startsection.

You can also easily test it:

\documentclass{article}

%normal catcodes:
\newcommand\test{$a_b$}

\begin{document}

\catcode`\$=11
\catcode`_=11
%changed catcodes:
$a_b$

\test
\end{document}
1
  • thank you ulrike. \textit{$a_b$} also works appropriately.
    – ivo Welch
    Feb 15, 2014 at 16:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .