4 people like it.

Automatically compile LaTeX documents

A simple script that automatically recompiles LaTeX documents when they are saved. Works nicely when editing papers in Atom and using SumatraPDF for preview (Sumatra automatically reloads PDF documents). Does not report errors or anything clever (!)

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
open System.IO
open System.Diagnostics

let path = @"C:\folder\with\my\papers"
let fsw = new FileSystemWatcher(path,"*.tex")
fsw.Changed.Add(fun _ -> 
  fsw.EnableRaisingEvents <- false
  let ps = 
    ProcessStartInfo
      ( FileName = @"C:\full\path\to\pdflatex.exe",
        Arguments = "-interaction=nonstopmode my-paper-name.tex",
        WorkingDirectory = path,
        UseShellExecute = false,
        CreateNoWindow = true )
  let p = Process.Start(ps)
  p.WaitForExit()
  fsw.EnableRaisingEvents <- true )

fsw.EnableRaisingEvents <- true
namespace System
namespace System.IO
namespace System.Diagnostics
val path : string

Full name: Script.path
val fsw : FileSystemWatcher

Full name: Script.fsw
Multiple items
type FileSystemWatcher =
  inherit Component
  new : unit -> FileSystemWatcher + 2 overloads
  member BeginInit : unit -> unit
  member EnableRaisingEvents : bool with get, set
  member EndInit : unit -> unit
  member Filter : string with get, set
  member IncludeSubdirectories : bool with get, set
  member InternalBufferSize : int with get, set
  member NotifyFilter : NotifyFilters with get, set
  member Path : string with get, set
  member Site : ISite with get, set
  ...

Full name: System.IO.FileSystemWatcher

--------------------
FileSystemWatcher() : unit
FileSystemWatcher(path: string) : unit
FileSystemWatcher(path: string, filter: string) : unit
event FileSystemWatcher.Changed: IEvent<FileSystemEventHandler,FileSystemEventArgs>
member System.IObservable.Add : callback:('T -> unit) -> unit
property FileSystemWatcher.EnableRaisingEvents: bool
val ps : ProcessStartInfo
Multiple items
type ProcessStartInfo =
  new : unit -> ProcessStartInfo + 2 overloads
  member Arguments : string with get, set
  member CreateNoWindow : bool with get, set
  member Domain : string with get, set
  member EnvironmentVariables : StringDictionary
  member ErrorDialog : bool with get, set
  member ErrorDialogParentHandle : nativeint with get, set
  member FileName : string with get, set
  member LoadUserProfile : bool with get, set
  member Password : SecureString with get, set
  ...

Full name: System.Diagnostics.ProcessStartInfo

--------------------
ProcessStartInfo() : unit
ProcessStartInfo(fileName: string) : unit
ProcessStartInfo(fileName: string, arguments: string) : unit
val p : Process
Multiple items
type Process =
  inherit Component
  new : unit -> Process
  member BasePriority : int
  member BeginErrorReadLine : unit -> unit
  member BeginOutputReadLine : unit -> unit
  member CancelErrorRead : unit -> unit
  member CancelOutputRead : unit -> unit
  member Close : unit -> unit
  member CloseMainWindow : unit -> bool
  member EnableRaisingEvents : bool with get, set
  member ExitCode : int
  ...

Full name: System.Diagnostics.Process

--------------------
Process() : unit
Process.Start(startInfo: ProcessStartInfo) : Process
Process.Start(fileName: string) : Process
Process.Start(fileName: string, arguments: string) : Process
Process.Start(fileName: string, userName: string, password: System.Security.SecureString, domain: string) : Process
Process.Start(fileName: string, arguments: string, userName: string, password: System.Security.SecureString, domain: string) : Process
Process.WaitForExit() : unit
Process.WaitForExit(milliseconds: int) : bool
Raw view New version

More information

Link:http://fssnip.net/qu
Posted:1 years ago
Author:Tomas Petricek
Tags: file , process , latex