Did you know ... Search Documentation:

# Package "switex"

Title: Literate programming with LaTeX and Prolog Not rated. Create the first rating! 0.0.7 d4c2bbd692ea1d67178f7252ea9b50cfb04ccf70 Samer Abdallah https://github.com/samer--/switex/raw/master/release/switex-0.0.7.tgz

## Reviews

No reviews. Create the first review!.

0.0.13836bd3b0feb2173744fef0ed92831ffca743f711https://github.com/samer--/switex/raw/master/release/switex-0.0.1.tgz
0.0.29b379b0b1912a7677613711121ea50e91edc4a051https://github.com/samer--/switex/raw/master/release/switex-0.0.2.tgz
0.0.3b2b5b8102659cd2cd9e675e2a7e37463f67c58d81https://github.com/samer--/switex/raw/master/release/switex-0.0.3.tgz
0.0.46c003c72af826812eb4b3f8129d71926173452b21https://github.com/samer--/switex/raw/master/release/switex-0.0.4.tgz
0.0.5d40fda9fc56d815214c3762d7d6ecf677a835e861https://github.com/samer--/switex/raw/master/release/switex-0.0.5.tgz
0.0.6686ede0690fce3ab0fb6f88d5ec651c752557fcb1https://github.com/samer--/switex/raw/master/release/switex-0.0.6.tgz
0.0.7d4c2bbd692ea1d67178f7252ea9b50cfb04ccf7013https://github.com/samer--/switex/raw/master/release/switex-0.0.7.tgz

# switex

LaTex and Prolog code to allow calling Prolog from LaTeX

This package allows LaTeX code to call Prolog to generate LaTeX content which is inserted into the document at the point where Prolog is called. It works by setting up a conversation between two running processes: pdflatex on one side and SWI Prolog on the other, communicating via their standard input and output streams. This system was inspired by Jonathan Fine's QATEX system: http://qatex.sourceforge.net/

## Prerequisites

• TeX installation

## Implementation details

The Prolog side of the system is implemented in prolog/switex.pl, with latex.pl supplying a DCG for writing out LaTeX code. The TeX side is implemented in tex/switex.sty, which writes requests for content on its standard output stream, and expects an answer on standard input. Currenty, the Prolog side also communicates on standard input and output streams. The two process are setup up with communicating pipes using a bash coprocess (see coproc in bash documentation). This setup is a little clumsy and fragile at the moment, so at some point, it will be replaced with Prolog code to start the pdflatex process.

In use, pdflatex produces a fair amount of output, which is ignored. When a Prolog computation is requested from the LaTeX side using the \swi macro, the request is written to standard output in the form

`\Q=<goal>.<return>`

with <goal> replaced by a valid Prolog goal terminated by a period as is normal in Prolog. The Prolog process recognises this an runs <goal>, collecting anything written to current\_output Prolog stream. It then replies to LaTeX with

`{<collected output>}<return>`

LaTeX receives this inserts <collected output> at the point where the \swi macro was called, almost as if it were written there in there in the first place, though there are certain limitations. One of these is that <collected output> cannot involve any of the verbatim macros that various LaTeX packages provide.

## Installation

If you install the Prolog side of things as an SWI package, then switex.pl and latex.pl should be available as Prolog modules.

The shell script in bin/switex should be copied or linked to somewhere on your PATH.

The TeX file tex/switex.sty should be copied or linked to somewhere in your TeX tree.

## Testing

Go into the test directory and run the switex command against test.tex:

`\$ switex test.tex`

This should produce test.pdf, which should look similar to http://github.com/samer--/switex/raw/master/test/test-sample.pdf

## Bugs

The communication between TeX and Prolog is somewhat fragile. In particular, if the Prolog query written out by \swi or \swiverb appears to be an incomplete Prolog term, then the Prolog side will hang waiting for its completion, leading to a deadlock. Similarly, if the Prolog side writes back an incomplete TeX group, then TeX will hang waiting for its completion. Currently, there is no way to recover from this situation, but typing Ctrl-C at the terminal or sending a SIGINT will kill both processes.

## Contents of pack "switex"

Pack contains 7 files holding a total of 11.6K bytes.
{"extraction_info": {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9523670077323914, "perplexity": 5441.186999756006}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-43/segments/1539583514314.87/warc/CC-MAIN-20181021181851-20181021203351-00087.warc.gz"}