     # don't display a summary
     @messages.setSummary summary: ''
 
+    # close the console if we switch to a non-LaTeX view
+    disposable.add atom.workspace.onDidStopChangingActivePaneItem (item) =>
+      @messages.close() unless item?.getGrammar?().scopeName is 'text.tex.latex'
+
   destroy: ->
     @messages.panel?.destroy()
     @messages.panel = undefined
+    disposable.dispose()
 
   serialize: ->
     messagePanelView:

module.exports =
class LTConsole
  constructor: (state) ->
    setupLogCss()

    unless state?.messagePanelView?

{CompositeDisposable} = require 'atom'
path = require 'path'

disposable = undefined

# terrible hack to use the editor font
setupLogCss = ->
