kisonecat / web2js

Convert TeX's pascal to javascript
Other
114 stars 17 forks source link

Create Docker environment #10

Open nosuke23 opened 3 years ago

nosuke23 commented 3 years ago

web2js has some dependencies to produce core.dump. It is hard to setup the local environment, therefore I want the Docker environment.

FROM adnrv/texlive:full 

# Update tex packages
RUN tlmgr update --self --all

ARG WORKDIR=/usr/var
WORKDIR ${WORKDIR}

# Install apt pacakges
RUN apt update && apt install -y \
  build-essential \
  cmake \
  git \
  libkpathsea-dev \
  python3-pip

# Install npm and node
ARG NODE_MAJOR_VERSION=14
ARG NODE_MINOR_VERSION=14.18.1
RUN wget https://deb.nodesource.com/node_${NODE_MAJOR_VERSION}.x/pool/main/n/nodejs/nodejs_${NODE_MINOR_VERSION}-deb-1nodesource1_amd64.deb \
  && apt install ./nodejs_${NODE_MINOR_VERSION}-deb-1nodesource1_amd64.deb \
  && rm nodejs_${NODE_MINOR_VERSION}-deb-1nodesource1_amd64.deb

# Install binaryen
ARG BINARYEN_VERSION=91
RUN wget https://github.com/WebAssembly/binaryen/archive/refs/tags/version_${BINARYEN_VERSION}.tar.gz \
  && tar -zxf version_${BINARYEN_VERSION}.tar.gz \
  && cd binaryen-version_${BINARYEN_VERSION} \
  && cmake . && make \
  && make install \
  && cd ../ && rm -rf binaryen-version_${BINARYEN_VERSION} version_${BINARYEN_VERSION}.tar.gz

# Install node packages
COPY package.json ${WORKDIR}/
RUN npm install

# Build
COPY . ${WORKDIR}/

# Produce tex.wasm and core.dump
RUN make core.dump

# Compile sampleLatex.tex by running
# RUN node tex.js sample/sampleLatex

This is my Dockerfile but ! I can't read TEX.POOL. error has occurred at node initex.js.

The following is that log.

! I can't read TEX.POOL.
[Object: null prototype] {
  '0': Memory [WebAssembly.Memory] {},
  getStackPointer: [Function: 20],
  setStackPointer: [Function: 21],
  main: [Function: 385],
  asyncify_start_unwind: [Function: 386],
  asyncify_stop_unwind: [Function: 387],
  asyncify_start_rewind: [Function: 388],
  asyncify_stop_rewind: [Function: 387]
}
! I can't read TEX.POOL.

This message is sent out from the source file but I don't know what is needed or wrong. tex.pool file is certainly exist by tangle. How can I fix it?

thatvideoshopguy commented 1 year ago

@nosuke23,

I noticed your post on the TeX Stack Exchange and subsequent issues here on GitHub. I'm working on a similar endeavour with the Tikz Plugin for Obsidian using web2js and tikzjax. Have you made any progress on the Dockerfile issue above?

Here's the challenge I'm facing: After compiling core.dump and tex.wasm without the {pgfsys-ximera.def} driver, I ran into an issue where no input.dvi file was produced in the browser when using the tikjax build:

Error: Could not find file input.dvi
    at Module.readFileSync (run-tex.js:20437:8)
    at texify (run-tex.js:20936:51)

When running node initex.js (with the driver), I encountered this error:

This is e-TeX, Version 3.14159265-2.6 (INITEX)
**entering extended mode
LaTeX2e <2018-12-01>
(standalone.cls
Document Class: standalone 2018/03/26 v1.3a Class to compile TeX sub-files stan
dalone
(shellesc.sty

Package shellesc Warning: Shell escape disabled on input line 65.

) (ifluatex.sty) (ifpdf.sty) (ifxetex.sty) (xkeyval.sty (xkeyval.tex
(xkvutils.tex (keyval.tex)))) (standalone.cfg) (article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(size10.clo)))
*(xcolor.sty (color.cfg) (dvips.def) (svgnam.def))
*(tikz.sty (pgf.sty (pgfrcs.sty (pgfutil-common.tex (pgfutil-common-lists.tex))
(pgfutil-latex.def (everyshi.sty)) (pgfrcs.code.tex (pgf.revision.tex)))
(pgfcore.sty (graphicx.sty (graphics.sty (trig.sty) (graphics.cfg)))
(pgfsys.sty (pgfsys.code.tex (pgfkeys.code.tex (pgfkeysfiltered.code.tex))
(pgf.cfg) (pgfsys-ximera.def

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                      

l.10 \ProvidesFileRCS $H
                        eader: /cvsroot/pgf/pgf/generic/pgf/systemlay...
?

Below is my Dockerfile attempt, aiming to encapsulate the necessary steps:

FROM debian:buster

RUN apt-get update

# Add NodeSource repository for Node 12 as that's what was originally used
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -

# Essential packages
RUN apt-get install -y curl ca-certificates build-essential \
    libkpathsea6 libkpathsea-dev texlive-latex-base texlive-latex-extra \
    gzip python2.7 git nodejs

# Clean up
RUN apt-get -y autoclean && rm -rf /var/lib/apt/lists/*

# Set python2.7 as default python for node packages
RUN rm -f /usr/bin/python && ln -s /usr/bin/python2.7 /usr/bin/python

# Clone the git repos
RUN git clone --branch ww-modifications https://github.com/drgrice1/web2js.git /app/web2js
RUN git clone --branch ww-modifications https://github.com/drgrice1/tikzjax.git /app/tikzjax
RUN git clone --branch ww-modifications https://github.com/drgrice1/dvi2html.git /app/dvi2html

# Build web2js
WORKDIR /app/web2js
RUN npm install
RUN ./node_modules/.bin/jison parser.jison
RUN npm install wasm-opt@1.1.1
RUN npm build
RUN npm run generate-wasm
RUN npx wasm-opt --asyncify --pass-arg=asyncify-ignore-indirect --pass-arg=asyncify-imports@library.reset -O1 out.wasm -o tex.wasm

# Deleting the following line from initex.js fixes the error "Error: ! LaTeX Error: Missing \begin{document}."
RUN sed -i "s|&latex \\\\documentclass[margin=0pt]{standalone}\\\\def\\\\pgfsysdriver{pgfsys-ximera.def}|&latex \\\\documentclass[margin=0pt]{standalone}|g" /app/web2js/initex.js
RUN node initex.js

# Compress the wasm and dump files
RUN gzip tex.wasm
RUN gzip core.dump

# Copy to the tikzjax directory
RUN mv tex.wasm.gz /app/tikzjax
RUN mv core.dump.gz /app/tikzjax

# Build dvi2html separately as it fails when built with tikzjax
WORKDIR /app/dvi2html
RUN npm install
RUN npm run build

# Build tikzjax
WORKDIR /app/tikzjax

# Remove dvi2html from package.json
RUN sed -i '20d' package.json 
RUN npm install

# Copy dvi2html to node_modules
RUN cp -r /app/dvi2html node_modules

# RUN npm run devbuild
RUN npm run build
RUN npm run postbuild

CMD [ "/bin/bash" ]

For further details and my continued efforts, check my development branch here.

Any insights or feedback would be immensely appreciated.