16

I was asked to convert a file from LaTeX format to TeX format, so it could be compiled by TeX. I use LaTeX a lot, but I'm quite unfamiliar with TeX. And the file is pretty long. So I was wondering if there's software or trick could simplify a bit the task.

BTW, I haven't installed TeX on my Ubuntu machine because I think I can use pdftex to test if the file is compatible with TeX. Am I right?


Edit:

The reason that I need to do this is that my supervisor asked me to convert something that I wrote with LaTeX into TeX style because he only knows how to use TeX. So the file should not only be compiled by TeX, but the grammar should also be TeX style so my supervisor could understand and modify it.

NonalcoholicBeer
  • 551
  • 3
  • 13
  • 4
    LaTeX is written in TeX so you can (with a bit of effort) just simply \input latex.ltx at the start of your file and then process it with tex, but it is rather pointless, it just makes the input longer and the processing slower. – David Carlisle Jan 09 '13 at 16:43
  • 1
    @ablmf It would be worth specifying the 'rules' a bit more tightly here, as David is quite right that you could just input all of LaTeX with a little effort. Presumably you are supposed to use 'plain TeX' as the input format and therefore define any helper macros yourself. – Joseph Wright Jan 09 '13 at 16:49
  • 4
  • 8
    Your supervisor should know that plain tex is an example format called "basic macros" in the TeXBook and not intended for document production. It simply has no mechanisms for font handling or cross referencing or anything that you actually need in a modern document. Of course you can define them and people do which is fine, but inputting your own macros to define those things and inputting the latex sources are not really any different conceptually, and the latex sources have been tested rather more over the last 30 years or so – David Carlisle Jan 09 '13 at 17:47
  • 2
    As David says, plain TeX has very much more limited mechanisms than LaTeX. Your supervisor will have his/her own approach to these requirements, and it's simply not possible to automatically convert from LaTeX to what a plain TeX user feels is the 'correct' way (each plain user will be different). – Joseph Wright Jan 09 '13 at 17:56
  • 8
    ask your supervisor for a typical file of his to use as a model. it will almost certainly input some macro files -- perhaps eplain or amstex or manmac, to name several that have been used relatively widely in the past (and are still used by some old-timers). reasonable user documentation is available for at least the first two. also, what field is this in? with that information, you should be able to ask questions that would get more reasonable answers. even so, don't expect this to be a walk in the park. – barbara beeton Jan 09 '13 at 18:23

2 Answers2

40

Adding

\def\patterns#1{}
\catcode`\{=12
\let\newtoks\relax
\let\dump\relax
\let\+\relax
\let\newinsert\relax

% extra lines for 2019 latex release \let\newmarks\relax

\let\acute\relax \let\grave\relax \let\ddot\relax \let\tilde\relax \let\bar\relax \let\breve\relax \let\check\relax \let\hat\relax \let\vec\relax \let\dot\relax \let\widetilde\relax \let\widehat\relax

% end of addition

\input latex.ltx

To a LaTeX file makes it a plain TeX file.

This is a LaTeX answer I gave to a question earlier today which runs without error in pdftex as modified:

\def\patterns#1{}
\catcode`\{=12
\let\newtoks\relax
\let\dump\relax
\let\+\relax
\let\newinsert\relax
\let\newmarks\relax

\let\acute\relax \let\grave\relax \let\ddot\relax \let\tilde\relax \let\bar\relax \let\breve\relax \let\check\relax \let\hat\relax \let\vec\relax \let\dot\relax \let\widetilde\relax \let\widehat\relax

\input latex.ltx \documentclass[a4paper]{IEEEtran}

%\usepackage[ngerman]{babel} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lipsum,tabularx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Here, main documents begins %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document}

\title{FooBar} \author{Bar Foo,~\IEEEmembership{foobar@google.com}}

% The paper headers \markboth{FooBar 2013}% {FooBar2013}

% make the title area \maketitle

%% ----------------- %% | Main part | %% -----------------

\lipsum

\section{aaa} \noindent \begin{tabularx}{\linewidth}{@{} r X @{}} Step 1: & \lipsum[1] \ Step 2: & \lipsum[2] \ Step 3 ggggggg kk kk jj gg : & \lipsum[3] \ \end{tabularx}

\makeatletter \renewcommand*@IEEEiedmakelabel[1]{\hspace\labelsep \parbox[t][0pt][t]{\itemindent}{\raggedright\normalfont\bfseries #1}} \makeatother \section{bbb}

\begin{description}

\item[Step 1] \lipsum[1] \item[Step 2] \lipsum[2] \item[Step 3 ggggggg kk kk jj gg ] \lipsum[3] \end{description}

\makeatletter \renewcommand*@IEEEiedmakelabel[1]{\hspace\labelsep \makebox[\linewidth][l]{{\normalfont\bfseries #1}}} \makeatother \section{bbb}

\begin{description}

\item[Step 1] \lipsum[1] \item[Step 2] \lipsum[2] \item[Step 3 ggggggg kk kk jj gg ] \lipsum[3] \end{description}

\end{document}

David Carlisle
  • 757,742
  • 3
    WOW! Could you just please elaborate why the first 5 lines are necessary? – yo' Jan 09 '13 at 16:55
  • 8
    @tohecz you need to clobber \patterns as that sets up hyphenation and is only allowed in initex runs not typestting runs (just use the hyphenation in plain tex) \dump is similar (that dumps a format but is an error if executed in plain tex) the catcode of { is set back because latex explicitly tests that someone is doing this and gives an error message (as normally inputting latex.ltx into plain tex is a mistake) and the remaining ones are because \outer is a pointless irritant. – David Carlisle Jan 09 '13 at 17:00
  • 1
    I owe you one beer, David. :) – Paulo Cereda Jan 10 '13 at 10:56
  • 1
    Errm - you add LaTeX to a plain file, so you end up with a LaTeX document (not the other way round). – Martin Schröder Jan 10 '13 at 11:25
  • @MartinSchröder sorry I do not understand your comment. The above is a plain TeX file, it processes without error with pdftex and would generate errors if processed with pdflatex. – David Carlisle Jan 10 '13 at 11:48
  • @PauloCereda (I think you meant 1 more :-) – David Carlisle Jan 10 '13 at 11:48
  • 2
    Instead of using the pre-generated latex.fmt, you include the whole latex source at the beginning of the document, so it is no surprise it compiles with pdftex, but I think this is not the spirit of the question, since the syntax used in all document except the first six lines, is latex syntax (i.e: \begin/\end environments, font changing commands, sectioning commands, etc.) – JLDiaz Jan 10 '13 at 11:54
  • 1
    @JLDiaz but that is the point of the answer. As noted in the other answer the spirit of the question is not well defined. plain has no syntax or definitions for cross references or bibliography handling or font changing so any document "using plain tex" has to define some macros for that, and those macros (rather than plain itself) determine the document syntax. The macros I input are no different in principle from including manmac or any other macro set, apart from the fact that people recognise the name and the \begin syntax and have an emotional response that it is latex not plain tex. – David Carlisle Jan 10 '13 at 12:03
  • @DavidCarlisle Yes, I understood that, but perhaps the OP did not, since he accepted your answer even if it does not answer his question. I think that your last comment deserves to figure as part of your answer. – JLDiaz Jan 10 '13 at 12:06
  • 2
    @DavidCarlisle: But the document is actually a LaTeX document. Please try this (adding the six lines) with texbook.tex :-) – Martin Schröder Jan 10 '13 at 12:15
  • 3
    @MartinSchröder There is no difference in principle between this and texbook.tex both input macros (latex.ltx and manmac.tex respectively) and use some markup defined by those macros. As I comment above the macros you input determine the markup used, that is always the case with "plain TeX" files as plain itself has so little document level markup defined. Obviously if you input manmac before this document or latex.ltx before texbook you will get error. You appear to be saying that any document that defines a macro is no longer "plain tex" I do not accept that. – David Carlisle Jan 10 '13 at 12:49
  • You are cheating: by \input latex.ltx you're actually smuggling the LaTeX kernel code into the Plain format. – jarnosc Mar 30 '17 at 19:30
  • 1
    @erreka it's not smuggling and why is that cheating? that is the whole point of the answer. – David Carlisle Mar 30 '17 at 19:47
  • I think what the OP's advisor was asking was to convert the LaTeX file to Plain, so as to process the file without latex.ltx. What you proposed was a (clever) trick to let a call to [Plain] TeX process an unmodified LaTeX file. The trick may have fooled the OP's advisor (if they had latex.ltx et al. installed in their system, as they may be expected to do) into believing that it was a Plain file, but it was not. – jarnosc Mar 30 '17 at 19:53
  • @erreka but any plain tex document requires some macros to be input I could copy that file to foobar.wibble and put \input foobar.wibble apart from cultural bias against things called "latex" on the part of some plain tex users there is really no difference. any answer for a "plain tex version" of the original document is going to have to input macros for font handling, cross references etc that are not in plain. This one is no different. the above is a plain tex file (and is not latex) it runs without error with pdftex and gives errors with pdflatex. what other definition is there? – David Carlisle Mar 30 '17 at 20:12
  • @DavidCarlisle You're partly right: Plain is perhaps a little too stupid to typeset anything interesting, so it needs to be complemented with more macros; but I insist (with others, apparently) that by \input latex.ltx you are actually smuggling in LaTeX's kernel, thus turning the "Plain" file into a "LaTeX" file. Proof: the document's markup thereafter is massively LaTeX's. – jarnosc Mar 31 '17 at 00:38
  • 2
    @erreka the way the site works you are welcome to post another answer if you feel there is a better one. I think (along with the OP apparently since this is the accepted answer) that this is in fact the best answer to the question as originally posed. It is not particularly useful but that is the point of the answer: to highlight that the problem itself is not well posed. – David Carlisle Mar 31 '17 at 07:39
  • Sadly (or not!) this doesn't seem to work anymore. The \input latex.ltx gives a ! Incomplete \ifx; all text was ignored after line 397 on line 401. Possibly something about "long" stuff? – ShreevatsaR Jul 07 '17 at 19:53
  • @ShreevatsaR \outer not \long (fixed:-) – David Carlisle Jul 07 '17 at 19:58
  • @ShreevatsaR see the first comment I made above! – David Carlisle Jul 07 '17 at 20:07
  • @DavidCarlisle Ah I see! Thanks that makes sense (and funnily enough this post had been affected by the double backslash!) – ShreevatsaR Jul 07 '17 at 20:12
9

»So the file should not only be compiled by TeX, but the grammar should also be TeX style so my supervisor could understand and modify it.«

I'd be very surprised to see a full solution to this problem. One thing is that TeX can compile a file, but it is a completely other thing to convert LaTeX into readable TeX, which can be handled, revised, changed, amended, in short: be a basis for further writing.

Just as an example: 

The line \documentclass[pagesize, parskip=half, headings=big, english, DIV=calc, BCOR=5mm]{scrartcl} contains quite a lot of instructions. How in the world transfer this into plain TeX except including more or less the whole KOMA-script bundle into the file?

Maybe you tell us a bit more about your file and the intentions of your supervisor.

Keks Dose
  • 30,892
  • 2
    This looks like a comment. Would you like to change it into a comment, or do you plan to extend it to a real answer? – Stefan Kottwitz Jan 09 '13 at 18:16
  • 6
    This is no comment. This is an answer: what the OP would like to do, seems not possible, unfortunately. And to elaborate on the reasons for that, including an example, is not very readable in a comments field, besides that. – Keks Dose Jan 09 '13 at 18:18
  • Obviously there is a „solution“ to the problem you mentioned. See the other answer. This still leaves the superviser with a document he does not understand. – Keinstein Feb 25 '22 at 18:15