mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 11:53:40 -05:00
use TikzManager to create main file for pstool package
This commit is contained in:
parent
5b3ba50cb1
commit
34acce8bda
3 changed files with 25 additions and 7 deletions
|
@ -58,9 +58,9 @@ module.exports = CompileManager =
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
createTikzFileIfRequired = (callback) ->
|
createTikzFileIfRequired = (callback) ->
|
||||||
TikzManager.checkMainFile compileDir, request.rootResourcePath, resourceList, (error, usesTikzExternalize) ->
|
TikzManager.checkMainFile compileDir, request.rootResourcePath, resourceList, (error, needsMainFile) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
if usesTikzExternalize
|
if needsMainFile
|
||||||
TikzManager.injectOutputFile compileDir, request.rootResourcePath, callback
|
TikzManager.injectOutputFile compileDir, request.rootResourcePath, callback
|
||||||
else
|
else
|
||||||
callback()
|
callback()
|
||||||
|
|
|
@ -4,26 +4,28 @@ ResourceWriter = require "./ResourceWriter"
|
||||||
SafeReader = require "./SafeReader"
|
SafeReader = require "./SafeReader"
|
||||||
logger = require "logger-sharelatex"
|
logger = require "logger-sharelatex"
|
||||||
|
|
||||||
# for \tikzexternalize to work the main file needs to match the
|
# for \tikzexternalize or pstool to work the main file needs to match the
|
||||||
# jobname. Since we set the -jobname to output, we have to create a
|
# jobname. Since we set the -jobname to output, we have to create a
|
||||||
# copy of the main file as 'output.tex'.
|
# copy of the main file as 'output.tex'.
|
||||||
|
|
||||||
module.exports = TikzManager =
|
module.exports = TikzManager =
|
||||||
|
|
||||||
checkMainFile: (compileDir, mainFile, resources, callback = (error, usesTikzExternalize) ->) ->
|
checkMainFile: (compileDir, mainFile, resources, callback = (error, needsMainFile) ->) ->
|
||||||
# if there's already an output.tex file, we don't want to touch it
|
# if there's already an output.tex file, we don't want to touch it
|
||||||
for resource in resources
|
for resource in resources
|
||||||
if resource.path is "output.tex"
|
if resource.path is "output.tex"
|
||||||
logger.log compileDir: compileDir, mainFile: mainFile, "output.tex already in resources"
|
logger.log compileDir: compileDir, mainFile: mainFile, "output.tex already in resources"
|
||||||
return callback(null, false)
|
return callback(null, false)
|
||||||
# if there's no output.tex, see if we are using tikz/pgf in the main file
|
# if there's no output.tex, see if we are using tikz/pgf or pstool in the main file
|
||||||
ResourceWriter.checkPath compileDir, mainFile, (error, path) ->
|
ResourceWriter.checkPath compileDir, mainFile, (error, path) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
SafeReader.readFile path, 65536, "utf8", (error, content) ->
|
SafeReader.readFile path, 65536, "utf8", (error, content) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
usesTikzExternalize = content?.indexOf("\\tikzexternalize") >= 0
|
usesTikzExternalize = content?.indexOf("\\tikzexternalize") >= 0
|
||||||
logger.log compileDir: compileDir, mainFile: mainFile, usesTikzExternalize:usesTikzExternalize, "checked for tikzexternalize"
|
usesPsTool = content.indexOf("{pstool}") >= 0
|
||||||
callback null, usesTikzExternalize
|
logger.log compileDir: compileDir, mainFile: mainFile, usesTikzExternalize:usesTikzExternalize, usesPsTool: usesPsTool, "checked for packages needing main file as output.tex"
|
||||||
|
needsMainFile = (usesTikzExternalize || usesPsTool)
|
||||||
|
callback null, needsMainFile
|
||||||
|
|
||||||
injectOutputFile: (compileDir, mainFile, callback = (error) ->) ->
|
injectOutputFile: (compileDir, mainFile, callback = (error) ->) ->
|
||||||
ResourceWriter.checkPath compileDir, mainFile, (error, path) ->
|
ResourceWriter.checkPath compileDir, mainFile, (error, path) ->
|
||||||
|
|
|
@ -65,6 +65,22 @@ describe 'TikzManager', ->
|
||||||
@callback.calledWithExactly(null, false)
|
@callback.calledWithExactly(null, false)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "and the main file contains \\usepackage{pstool}", ->
|
||||||
|
beforeEach ->
|
||||||
|
@SafeReader.readFile = sinon.stub()
|
||||||
|
.withArgs("#{@compileDir}/#{@mainFile}")
|
||||||
|
.callsArgWith(3, null, "hello \\usepackage[random-options]{pstool}")
|
||||||
|
@TikzManager.checkMainFile @compileDir, @mainFile, @resources, @callback
|
||||||
|
|
||||||
|
it "should look at the file on disk", ->
|
||||||
|
@SafeReader.readFile
|
||||||
|
.calledWith("#{@compileDir}/#{@mainFile}")
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the callback with true ", ->
|
||||||
|
@callback.calledWithExactly(null, true)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "injectOutputFile", ->
|
describe "injectOutputFile", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@rootDir = "/mock"
|
@rootDir = "/mock"
|
||||||
|
|
Loading…
Reference in a new issue