[NTG-context] Set luatex cache directory path

Thangalin thangalin at gmail.com
Sun Apr 11 23:13:34 CEST 2021


$ sudo su -
$ rm -rf /opt/context
$ mkdir -p /opt/context
$ cd /opt/context
$ wget http://lmtx.pragma-ade.nl/install-lmtx/context-linux-64.zip
$ unzip *zip
$ export TEXMFCACHE=/tmp
$ sh install.sh
$ exit
$ cat test.tex
\starttext
Test
\stoptext
$ export TEXMFCACHE=/tmp
$ sudo rm -rf /tmp/luatex-cache
$ /opt/context/tex/texmf-linux-64/bin/mtxrun --autogenerate --script
mtx-context --autopdf test.tex
resolvers       | resolving | remembered file 'mtx-context.lua'
resolvers       | resolving | remembered file 'mtx-contexts.lua'
resolvers       | resolving | remembered file 'mtx-context.lua'
resolvers       | resolving | remembered file 'mtx-t-mtx-context.lua'
resolvers       | resolving | remembered file 'mtx-t-mtx-contexts.lua'
resolvers       | resolving | remembered file 'mtx-t-mtx-context.lua'
resolvers       | resolving | remembered file 'mtx-context.lua'
mtxrun          | unknown script 'mtx-context.lua' or 'mtx-mtx-context.lua'

If the cache directory isn't deleted, the PDF is generated. However, as
soon as the computer reboots, or the temporary directory is otherwise
erased, two runs are required.

I've addressed this in my code, but it's a little awkward and somewhat
brittle because the code cannot know what makes for a valid luatex-cache
directory:

    private boolean reinitialize() {
      // variable assignments ... exists = check for luatex-cache directory

      mArgs.clear();
      mArgs.add( TYPESETTER.getName() );

      if( exists ) {
        mArgs.add( "--autogenerate" );
        mArgs.add( "--script" );
        mArgs.add( "mtx-context" );
        mArgs.add( ... remaining args ... );
      }
      else {
        mArgs.add( "--generate" );
      }

      return exists;
    }

    private boolean typeset() throws Exception {
      return reinitialize() ? call() : call() && reinitialize() && call();
    }

    // Invoke ConTeXt to either typeset the document or generate the cache
directory
    public Boolean call() throws Exception {
      final var builder = new ProcessBuilder( mArgs );
      builder.directory( mDirectory.toFile() );

      final var cacheDir = getCacheDir();
      final var env = builder.environment();
      env.put( "TEXMFCACHE", cacheDir.toString() );

      builder.redirectOutput( DISCARD );
      builder.redirectError( DISCARD );

      final var process = builder.start();
      process.waitFor();
      final var exit = process.exitValue();
      process.destroy();
      return exit == 0;
    }

Also, unless my application installs ConTeXt, setting the TEXMFCACHE
directory before the installation begins will require asking users to do
this. Ideally, using the software would take the following steps:

1. Download text editor
2. Download and install ConTeXt (e.g., click link, extract archive, run
install.sh)
3. Run text editor
4. Export PDF (editor configures ConTeXt as required, reducing the number
of steps for end users)

At some point in the future, the editor may prompt the user for permission
to install ConTeXt on their behalf---to simplify step 2---but that's much
more effort.

Stay safe!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20210411/2da71c06/attachment.htm>


More information about the ntg-context mailing list