Version 6, TeX, and .sci files

Barry MacKichan's picture

Version 6, TeX, and .sci files

I’d like to address the assertion that Versions 6 of Scientific Word and Scientific WorkPlace are farther from their TeX roots than earlier versions. This is not true. Let me explain why. 

Version 5.5 and previous

In previous versions, the file on the disk was a TeX file, but not all TeX files were SW or SWP files. Our files were a subset of LaTeX; we supported all the major features of LaTeX, but to use other features, you had to use TeX fields and load additional packages. These files were then read into the program and converted to an internal form which looked like LaTeX at the local level, but differed considerably at the global level – paragraphs and higher order structures were kept in a database. Sometimes the internal form of the file would be written to the disk; this was called the fast load format and was deprecated in the later versions. For processing by LaTeX and for saving to the disk, the documents were written out as LaTeX again. A diagram of the chain of formats is: 

LaTeX subset
–>
Internal form
–>
LaTeX subset
 

The LaTeX file at the beginning of the chain need not be the same as the one at the end, even if you don’t make any editing changes; unrecognized LaTeX code will be converted to TeX fields, for example. The LaTeX file at the end is equivalent to the internal form; each can be generated from the other. But editing the end file is not supported – some edits may be recognized, others may generate new TeX fields, and others may render the file unreadable.

TeX and LaTeX files are simple ASCII (or Unicode) files, which makes them very portable, but they can reference other objects such as plots, graphics, and other TeX files. This makes managing multiple files much more difficult. For example, verifying that a graphics file is no longer used can be very tedious if there are many LaTeX files to check, since there is no information to say where the graphics file had been used.

Version 6

Now look at the corresponding diagram in version 6:

LaTeX subset
–>
XHTML file, CSS file
–>
LaTeX subset
 

It is the same diagram as before except the internal form has changed. 

What is a .sci file?

A .sci file is a zip file.
The file extension is sci rather than zip so that the operating system knows to start SW or SWP when you click on it, and not to unzip the file. On Windows, try using the File Explorer with the view that puts directories on the left and files on the right. On the left side, open the SWPDocs (or SWDocs) directory, and click on a sci file. In the pane on the right you will see several directories and at least one file, called main.xhtml, which is our internal format. There will be a tex directory if and only if the document has been previewed with TeX. Once the directory is there, it will always contain the last TeX file generated for this document. The other directories will be several or more of css, graphics, plots, gcache, and tcache. These are where the auxiliary files attached to the document live; this solves the problem of the document pieces lying scattered throughout the file system. If there are subdocuments, they will have files at the outer level, siblings of main.xhtml. So for the document foo, the TeX file will be foo.sci/tex/main.tex. In practical terms, it is the LaTeX file at the right end of the above diagrams. You can look at it (use the View/TeX File menu item in SW or SWP), or change it, but as before, if you change it, it has to be converted to our internal form (via File/Import TeX) to be used, and, as before, this can fail if you stray too far from common LaTeX. A much better way to change it is to insert a TeX field.

Why change the internal format?

For flexibility. In the previous versions, introducing a new LaTeX construct would require extending our internal format, which means that code to handle the display and behavior of the new object would have to be written in the core C++ code. The advent of browsers, HTML, XHTML, and CSS have given us the tools to handle the display of a large variety of versatile objects. The appearance of the object can be controlled by CSS (cascading style sheets) sheets. 

The conversion of LaTeX to XHTML is done by a reimplementation of the TeX macro processor. The rules for the translation of a LaTeX construct are given by TeX macros.

The conversion of XHTML to LaTeX is done with another standard technology, XSLT transformations. Thus the key transformations are done with standard, open-source tools, which will make it much easier for us to extend the capabilities of SW and SWP.

Thus, several of the key parts of the program now use open technologies – TeX, XSLT, CSS, and JavaScript. Not only will this make it easier for us to add new functionality in the future, but it will also be possible for third parties to extend the program. The underlying browser technology also makes supporting plugins and extensions possible.

I miss my TeX

If you really want to see the TeX you are generating, it is possible. The following describes a process we used frequently during the development when it seemed that the XSLT was not generating the correct TeX. It allowed us to tweak the TeX to determine how to change the generation. 

Most of the auxiliary programs such as pdflatex and xelatex are called through command or bash files, which makes it easy to change the programs that are run as well as the parameters they are given. For example, if you have TeXWorks installed on Windows and registered as the editor for the .tex extension, you could change our pdflatex.cmd file (after backing up the original) to read:

    rem @echo off  
    setlocal enabledelayedexpansion  
    pushd %1  
    %2.tex  
    echo done > sentinel  
    popd  

Then when you press the Preview tab, you will run TeXWorks instead of pdflatex, and you can run pdflatex after viewing or editing the TeX file. However, remember that changes you make won’t be saved unless you import the altered TeX file into SW or SWP. Again, it would be better to package your change in a TeX field.

yyh's picture

Thank you, Mr. MacKichan! It

Thank you, Mr. MacKichan! It is very nice that you explained these.
At this moment, the "subset" of version 6 is obviously much smaller than that of version 5.5. Hope you will make version 6 better soon.

texab's picture

Thanks Barry, I feel I can

Thanks Barry, I feel I can post one of my questions now. It has to do with my invoices but it is of general interest.

In source I see:
environment type="TeXABReferens"> bodyText>Mikael Möller /bodyText> environment>
environment type="KreditTid"> bodyText>30 /bodyText>/environment>

Sorry bu I had to remove lots of <

The word "TeXABReferens" should be set in one colour and the text in another. Immediately after (not on a new line) the text Mikael Möller should be written. Any extra rows like address should be written under the name and lined up vertically. Something like this

TeXABReferens Mikael Möller
my adress
my country

The m should be under M, and next m under m. How do I make this happen?

jsmeyer's picture

Thank you, Mr. Mackichan,

Thank you, Mr. Mackichan,
Your explanation was informative and interesting. I always enjoy a bit of "inside baseball".
Pax
Jim Meyer