Re: [NTG-context] Set luatex cache directory path

2021-04-11 Thread Thangalin
$ 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!
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-11 Thread Hans Hagen

On 4/11/2021 1:30 AM, Thangalin wrote:

Are two runs always required to generate a PDF when TEXMFCACHE is set?

$ sudo su -
$ mkdir -p /opt/context
$ cd /opt/context
$ wget http://lmtx.pragma-ade.nl/install-lmtx/context-linux-64.zip 


$ unzip *zip
$ sh install.sh
$ exit
$ cat test.tex
\starttext
Test
\stoptext
$ export TEXMFCACHE=/tmp
$ rm -rf $TEXMFCACHE/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'
$ /opt/context/tex/texmf-linux-64/bin/mtxrun --script context --version
mtx-context     | current version: 2021.04.10 17:09
$ mtxrun --autogenerate --script mtx-context --autopdf test.tex
...
mkiv lua stats  > runtime: 0.432 seconds, 1 processed pages, 1 shipped 
pages, 2.315 pages/second

system          | total runtime: 3.318 seconds of 3.372 seconds

The first run fails; the second run succeeds.

If TEXMFCACHE is not set, then the first run succeeds. If TEXMFCACHE is 
set to any non-empty value and $TEXMFCACHE/luatex-cache has not been 
created, mtxrun always terminates with the same unknown script error.


What am I missing to ensure that ConTeXt will create luatex-cache in 
/tmp when TEXMFCACHE is set and successfully build the PDF on first run?

what happens if you also set TEXMFCACHE before running install.sh

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-10 Thread Thangalin
Are two runs always required to generate a PDF when TEXMFCACHE is set?

$ sudo su -
$ mkdir -p /opt/context
$ cd /opt/context
$ wget http://lmtx.pragma-ade.nl/install-lmtx/context-linux-64.zip
$ unzip *zip
$ sh install.sh
$ exit
$ cat test.tex
\starttext
Test
\stoptext
$ export TEXMFCACHE=/tmp
$ rm -rf $TEXMFCACHE/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'
$ /opt/context/tex/texmf-linux-64/bin/mtxrun --script context --version
mtx-context | current version: 2021.04.10 17:09
$ mtxrun --autogenerate --script mtx-context --autopdf test.tex
...
mkiv lua stats  > runtime: 0.432 seconds, 1 processed pages, 1 shipped
pages, 2.315 pages/second
system  | total runtime: 3.318 seconds of 3.372 seconds

The first run fails; the second run succeeds.

If TEXMFCACHE is not set, then the first run succeeds. If TEXMFCACHE is set
to any non-empty value and $TEXMFCACHE/luatex-cache has not been created,
mtxrun always terminates with the same unknown script error.

What am I missing to ensure that ConTeXt will create luatex-cache in /tmp
when TEXMFCACHE is set and successfully build the PDF on first run?

Thank you!
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-06 Thread Hans Hagen

On 4/6/2021 8:59 PM, Thangalin wrote:

Thanks Aditya.

What do you think of changing the default luatex-cache directory to the 
system's temporary directory? Consider:


  * The $HOME directory is sacrosanct (4784 people agree:
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1575053
)
  * The temp directory is cleared on Linux (Unix?) system reboots;
purged during regular Windows upkeep
  * The temp directory is writable by default
  * Changing the location requires calling an additional program, which
isn't obvious (principle of least astonishment)


Do you really want to recahe fonts so often?


My text editor invokes ConTeXt like:

     if( TYPESETTER.canRun() ) {
       env.put( "TEXMFCACHE", System.getProperty( "java.io.tmpdir" ) );

       mArgs.add( TYPESETTER.getName() );
       mArgs.add( .. --path .. --purge .. --batch .. --result .. 
--environment .. etc. );

       mArgs.add( inputFilename );
     }


--batch only makes sense for an unattended run
--purging every time can lead to extra runs

The first line ensures that "context" is an executable located in a PATH 
directory. The second line attempts to change the luatex-cache 
directory. The remaining lines configure the command-line arguments 
prior to running ConTeXt.


Fearing flaming wrath from users, an additional mtxrun call is required, 
which incurs overhead:


  * Check for mtxrun executable
  * Run mtxrun each time


see aditya's reply ... the --autogenerate is clever enough not to do 
redundant things (and context knows when it has been updated so ...)


This would work but feels like a leaky abstraction (i.e., the context 
executable should honour TEXMFCACHE without needing to invoke mtxrun 
because context creates the luatex-cache directory).
see aditya's reply ... quite some effort has gone into making sure 
context starts up fast so i'm not going to advocate a different practice


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-06 Thread Thangalin
Perfect, thank you.

Will be Wikified.
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-06 Thread Aditya Mahajan
On Tue, 6 Apr 2021, Thangalin wrote:

> Thanks Aditya.
> 
> What do you think of changing the default luatex-cache directory to the
> system's temporary directory? Consider:
> 
>- The $HOME directory is sacrosanct (4784 people agree:
>https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1575053)
>- The temp directory is cleared on Linux (Unix?) system reboots; purged
>during regular Windows upkeep
>- The temp directory is writable by default
>- Changing the location requires calling an additional program, which
>isn't obvious (principle of least astonishment)

Use:

mtxrun --autogenerate --script mtx-context ...

Aditya
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-06 Thread Thangalin
Thanks Aditya.

What do you think of changing the default luatex-cache directory to the
system's temporary directory? Consider:

   - The $HOME directory is sacrosanct (4784 people agree:
   https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1575053)
   - The temp directory is cleared on Linux (Unix?) system reboots; purged
   during regular Windows upkeep
   - The temp directory is writable by default
   - Changing the location requires calling an additional program, which
   isn't obvious (principle of least astonishment)

My text editor invokes ConTeXt like:

if( TYPESETTER.canRun() ) {
  env.put( "TEXMFCACHE", System.getProperty( "java.io.tmpdir" ) );

  mArgs.add( TYPESETTER.getName() );
  mArgs.add( .. --path .. --purge .. --batch .. --result ..
--environment .. etc. );
  mArgs.add( inputFilename );
}

The first line ensures that "context" is an executable located in a PATH
directory. The second line attempts to change the luatex-cache directory.
The remaining lines configure the command-line arguments prior to running
ConTeXt.

Fearing flaming wrath from users, an additional mtxrun call is required,
which incurs overhead:

   - Check for mtxrun executable
   - Run mtxrun each time

This would work but feels like a leaky abstraction (i.e., the context
executable should honour TEXMFCACHE without needing to invoke mtxrun
because context creates the luatex-cache directory).

Thoughts?
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Set luatex cache directory path

2021-04-06 Thread Aditya Mahajan
On Mon, 5 Apr 2021, Thangalin wrote:

> Peter Münster once asked:
> 
> > What should I do please, to prevent ConTeXt from creating
> $HOME/luatex-cache?
> 
> I'd like to do the same:
> 
> $ cd $HOME
> $ ls luatex-cache
> ls: cannot access 'luatex-cache': No such file or directory
> $ context test.tex
> $ ls luatex-cache/
> context
> $ rm -rf luatex-cache
> $ export TEXMFCACHE=/tmp

Add

$ mtxrun --generate

> $ context test.tex
> mtxrun  | unknown script 'mtx-context.lua' or 'mtx-mtx-context.lua'
> $ export TEXMFCACHE=
> $ context --version
> ...
> mtx-context | current version: 2021.03.31 18:04
> 
> What environment variable must change to set the luatex-cache directory?

Aditya___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] Set luatex cache directory path

2021-04-05 Thread Thangalin
Peter Münster once asked:

> What should I do please, to prevent ConTeXt from creating
$HOME/luatex-cache?

I'd like to do the same:

$ cd $HOME
$ ls luatex-cache
ls: cannot access 'luatex-cache': No such file or directory
$ context test.tex
$ ls luatex-cache/
context
$ rm -rf luatex-cache
$ export TEXMFCACHE=/tmp
$ context test.tex
mtxrun  | unknown script 'mtx-context.lua' or 'mtx-mtx-context.lua'
$ export TEXMFCACHE=
$ context --version
...
mtx-context | current version: 2021.03.31 18:04

What environment variable must change to set the luatex-cache directory?

Thank you!
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___