-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when loading external ressources with relatives paths #2
Comments
Ooh, sorry about that. Let's see. I'll have to think about this. I'm at work so can't fully debug at the moment. I don't think the Ah, okay. So the actual code that calls https://github.com/mikolalysenko/node-latex/blob/master/texwrapper.js#L110-L118 I believe it makes a temporary directory and runs latex there, so relative includes will be relative to |
Thanks I will take a look ! |
Actually, upon further thought, I think maybe what you're really up against here is shoehorning tex into a streaming gulp approach. Tex deals in multiple input and ouput files, so the best that can be done—and precisely what this plugin does—is to move latex into a tmp folder and grab the result so that it feels like file streaming and makes gulp happy. My advice: I think gulp-spawn might actually be what you're interested in, and perhaps I should note this in the docs. If you do have multiple inputs, then—correct me if I'm wrong—it sounds like you're perhaps more interested in running latex programmatically, which sounds like maybe a better fit for gulp-spawn. The majority of this code exists and jumps through hoops to get latex to work alongside file streaming, but you may not need that. |
So long story short, I think this behavior, unfortunately, makes sense due to the nature of latex, but if you can elaborate on your use case, I'm glad to brainstorm 😄 |
Hi again ! You were right, the https://www.npmjs.com/package/latex-file After changing 'use strict';
var latex = require('latex-file').latex;
var through = require('through2');
var rawBody = require('raw-body');
var gutil = require('gulp-util');
var path = require('path');
module.exports = gulpLatex;
function gulpLatex(options) {
options = options || {};
// Sanitize against 'pdf' or 'dvi':
options.format = {pdf: 'pdf', dvi: 'dvi'}[options.format] || 'pdf';
return through.obj( function( file, enc, cb ) {
var self = this;
// Pass null files
if( file.isNull() ) {
cb(null,file);
return;
}
// Compilation
options.pipe_in_stream = true;
var outDir = path.dirname(file.path);
options.out_directory = outDir;
latex(file.path, options, function(err){
if(err) {
console.error(err);
}
cb(null,file);
});
});
} Could be cool right ? |
I am experiencing the same problem. Using I wan't to build my LaTeX files from One file is trying to import structure.tex. I have the following error :
Is there another way to automatically save to pdf my tex files on debian ? |
@kopax - Sorry for the delay! Was away from the computer for the weekend. What about
Would need to think about getting the See mikolalysenko/node-latex#11 for upstream issue. |
And @gurdilou — I've been distracted and have been meaning to sit down and process these subtleties, but thanks for the interest and solution! |
@rreusser Finally made my own solution : gulpfile.js
pdf_all.sh
Using gulp-watch, I am able to automatically rebuild my tex files recursively on change. |
@rreusser I noticed, that you referred to node-latex for a possible problem upstream (https://github.com/mikolalysenko/node-latex/blob/master/texwrapper.js#L110-L118) If i read it correctly, the spawn command runs pdflatex inside the temp folder (this is in the options with cwd: dirpath). So the caller's original working directory is not respected. A possible fix might be to run pdflatex in the original working path and referencing files from there. This snippet should fix this in node-latex: tex_file.on("close", function() {
//Invoke LaTeX
var tex = spawn(tex_command, [
"-interaction=nonstopmode",
// reference files from current working path
"-output-directory=" + dirpath,
input_path
], {
// don't change process's working path
// cwd: dirpath,
env: process.env
}); Sorry, I can't make a pull request for node-latex right now, as I can't properly test this fix and also I'm not very experienced with GitHub yet. My fork can be found here: https://github.com/lqdchrm/node-latex So now using relative paths in tex-files with gulp-latex (after applying the fix above to node-latex) should work, even if you change the process's working directory. Might work for you guys :-) gulp.task('latex2pdf', function () {
process.chdir('./docs/latex/');
return gulp.src(['./document.tex'])
.pipe(plumber())
.pipe(latex())
.pipe(gulp.dest('./out'));
}); |
+1 for merging |
Thanks @kopax, your bash script + shell task made it work for me as well 👍 |
Glad the solution works for people! If anyone wants to make a PR to solve this, I'd be glad to accept. Just short on time at the moment. |
Hi, thanks for the plugin !
The plugin seems not able to load external resources. E.g. :
whereas
I double checked paths. Do you change the working directory, or things like that ?
Thank you.
The text was updated successfully, but these errors were encountered: