From dd35c5d88b841643688e35a5922ad8bdb33a8445 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 21 Mar 2017 11:36:08 +0000 Subject: [PATCH] check for \tikzexternalize directly instead of \usepackage{tikz} and \usepackage{pgf} --- services/clsi/app/coffee/TikzManager.coffee | 8 +++---- .../clsi/test/unit/coffee/TikzManager.coffee | 23 ++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/services/clsi/app/coffee/TikzManager.coffee b/services/clsi/app/coffee/TikzManager.coffee index 7766bc12b2..cfa13321a6 100644 --- a/services/clsi/app/coffee/TikzManager.coffee +++ b/services/clsi/app/coffee/TikzManager.coffee @@ -21,11 +21,9 @@ module.exports = TikzManager = return false _includesTikz: (resource) -> - # check if we are loading tikz or pgf - content = resource.content.slice(0,4096) - if content.indexOf("\\usepackage{tikz") >= 0 - return true - else if content.indexOf("\\usepackage{pgf") >= 0 + # check if we are using tikz externalize + content = resource.content.slice(0,65536) + if content.indexOf("\\tikzexternalize") >= 0 return true else return false diff --git a/services/clsi/test/unit/coffee/TikzManager.coffee b/services/clsi/test/unit/coffee/TikzManager.coffee index 4c99daacf7..8174b4a2e2 100644 --- a/services/clsi/test/unit/coffee/TikzManager.coffee +++ b/services/clsi/test/unit/coffee/TikzManager.coffee @@ -11,28 +11,22 @@ describe 'TikzManager', -> "logger-sharelatex": @logger = {log: () ->} describe "needsOutputFile", -> - it "should return true if there is a usepackage{tikz}", -> + it "should return true if there is a \\tikzexternalize", -> + @TikzManager.needsOutputFile("main.tex", [ + { path: 'foo.tex' }, + { path: 'main.tex', content:'foo \\usepackage{tikz} \\tikzexternalize' } + ]).should.equal true + + it "should return false if there is no \\tikzexternalize", -> @TikzManager.needsOutputFile("main.tex", [ { path: 'foo.tex' }, { path: 'main.tex', content:'foo \\usepackage{tikz}' } - ]).should.equal true - - it "should return true if there is a usepackage{pgf}", -> - @TikzManager.needsOutputFile("main.tex", [ - { path: 'foo.tex'}, - { path: 'main.tex', content:'foo \\usepackage{pgf}' } - ]).should.equal true - - it "should return false if there is no usepackage{tikz} or {pgf}", -> - @TikzManager.needsOutputFile("main.tex", [ - { path: 'foo.tex' }, - { path: 'main.tex', content:'foo \\usepackage{bar}' } ]).should.equal false it "should return false if there is already an output.tex file", -> @TikzManager.needsOutputFile("main.tex", [ { path: 'foo.tex' }, - { path: 'main.tex' }, + { path: 'main.tex', content:'foo \\usepackage{tikz} \\tikzexternalize' }, { path: 'output.tex' } ]).should.equal false @@ -44,6 +38,7 @@ describe 'TikzManager', -> @content = ''' \\documentclass{article} \\usepackage{tikz} + \\tikzexternalize \\begin{document} Hello world \\end{document}