         console.log err
     return false
 
+  writeLocalCfg: (rootpath) ->
+    if @lastCfgTime? and Date.now() - @lastCfgTime < 200 or\
+       !atom.workspace.getActiveTextEditor()?
+      return @config?
+    @lastCfgTime = Date.now()
+    rootDir = @rootDir()
+    return false if !rootDir?
+    if '.latexcfg' in fs.readdirSync rootDir
+      try
+        filePath = path.join rootDir, '.latexcfg'
+        fileContent = fs.readFileSync filePath, 'utf-8'
+        @config = JSON.parse fileContent
+        @config.root = rootpath
+        fs.writeFileSync filePath, JSON.stringify @config
+        return true
+      catch err
+        console.log err
+    else
+      filePath = path.join rootDir, '.latexcfg'
+      @config = JSON.stringify {"root": rootpath}
+      fs.writeFileSync filePath, JSON.stringify @config
+      return true
+    return false
+
   isTexFile: (name) ->
     @latex.manager.loadLocalCfg()
     if path.extname(name) in ['.tex','.tikz'] or \
         @latex.manager.config?.latex_ext?.indexOf(path.extname(name)) > -1
       return true
     return false
-    
+
   getDocandExt: (fpath) ->
     if !fpath
       @latex.logger.debuglog.info("Invalid tex path")

    for ext in extnames
      if path.basename(fpath).endsWith(ext)
        return [path.basename(fpath).replace(ext,''), ext.slice(1)]
        
  findMain: (here) ->
    result = @findMainSequence(here)
    if result and !fs.existsSync(@latex.mainFile)

    findFiles = () =>
        @latex.texFiles = [ @latex.mainFile ]
        @latex.bibFiles = []
        @findDependentFiles(@latex.mainFile)
    if @disable_watcher or @watchRoot()
      findFiles()
      if @disable_watcher
