-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
executable file
·164 lines (143 loc) · 5.84 KB
/
main.nf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env nextflow
/*
================================================================================
= C O M P I L E - L A T E X =
================================================================================
@Author
Maxime Garcia <max.u.garcia@gmail.com> [@MaxUlysse]
--------------------------------------------------------------------------------
@Homepage
https://github.com/MaxUlysse/compile-latex
--------------------------------------------------------------------------------
@Documentation
https://github.com/MaxUlysse/compile-latex/blob/master/README.md
--------------------------------------------------------------------------------
@Licence
https://github.com/MaxUlysse/compile-latex/blob/master/LICENSE
--------------------------------------------------------------------------------
Process overview
- RunXelatex
Run xelatex, optionally biber and xelatex and finally xelatex again
================================================================================
= C O N F I G U R A T I O N =
================================================================================
*/
if (params.help) exit 0, helpMessage()
if (!params.tex) exit 1, 'No tex file, see --help for more information'
biblio = file(params.biblio)
pictures = file(params.pictures)
tex = Channel.fromPath(params.tex)
/*
================================================================================
= P R O C E S S =
================================================================================
*/
startMessage()
process RunXelatex {
tag {tex}
publishDir params.outDir, mode: 'link'
input:
file biblio
file pictures
file tex
output:
file("*.pdf") into pdf
script:
notes = params.notes == '' ? "" : "\"\\PassOptionsToClass{notes}{beamer}\\input{$tex}\""
notes = params.notesOnly == '' ? notes : "\"\\PassOptionsToClass{notes=only}{beamer}\\input{$tex}\""
xelatexScript = notes == '' ? "xelatex -shell-escape ${tex}" : "xelatex -shell-escape ${notes}"
biberScript = biblio.exists() ? "biber ${tex.baseName}.bcf ; ${xelatexScript}" : ""
renameScript = params.outName == '' ? "" : "cp ${tex.baseName}.pdf ${params.outName}"
"""
${xelatexScript}
${biberScript}
${xelatexScript}
${renameScript}
"""
}
/*
================================================================================
= F U N C T I O N S =
================================================================================
*/
def compileLatex_ascii() {
println ""
println " _.-´`-._ _ _ _ _"
println " _.-´ T X `-._ (_) | | | | |"
println "|`-._ E _.-´| ___ ___ _ __ ___ _ __ _| | ___ | | __ _| |_ _____ __"
println "|--. `-.__.-´ . | / __/ _ \\| '_ ` _ \\| '_ \\| | |/ _ \\___| |/ _` | __/ _ \\ \\/ /"
println "| \\.---| . | | | | (_| (_) | | | | | | |_) | | | __/___| | (_| | || __/> <"
println "|---´\\ | | | | | \\___\\___/|_| |_| |_| .__/|_|_|\\___| |_|\\__,_|\\__\\___/_/\\_\\"
println " `-._ `--| | '_.-´ | |"
println " `-._|_.-´ |_|"
println ""
}
def compileLatexMessage() {
// Display compile-latex message
log.info "compile-latex ~ ${workflow.manifest.version} - " + this.grabRevision() + (workflow.commitId ? " [$workflow.commitId]" : "")
}
def grabRevision() {
// Return the same string executed from github or not
return workflow.revision ?: workflow.commitId ?: workflow.scriptId.substring(0,10)
}
def helpMessage() {
// Display help message
this.compileLatexMessage()
log.info " Usage:"
log.info " nextflow run MaxUlysse/compile-latex --tex <input.tex>"
log.info " --tex"
log.info " Compile the given tex file"
log.info " --biblio"
log.info " Specify the bibliography"
log.info " Default: biblio.bib"
log.info " --notes"
log.info " Generate notes with presentation"
log.info " --pictures"
log.info " Specify in which directory are the pictures"
log.info " Default: pictures/"
log.info " --tag"
log.info " Specify with tag to use for the docker container"
log.info " --outName"
log.info " Specify output name"
log.info " --outDir"
log.info " Specify output directory"
log.info " --help"
log.info " You're reading it"
}
def minimalInformationMessage() {
// Minimal information message
log.info "Command Line: " + workflow.commandLine
log.info "Launch Dir : " + workflow.launchDir
log.info "Work Dir : " + workflow.workDir
log.info "Container : " + workflow.container
log.info "Tex file(s) : " + params.tex
if (biblio.exists()) log.info "Bibliography: " + params.biblio
if (pictures.exists()) log.info "Pictures in : " + params.pictures
}
def nextflowMessage() {
// Nextflow message (version + build)
log.info "N E X T F L O W ~ version " + workflow.nextflow.version + " " + workflow.nextflow.build
}
def startMessage() {
// Display start message
this.compileLatex_ascii()
this.compileLatexMessage()
this.minimalInformationMessage()
}
workflow.onComplete {
// Display end message
this.nextflowMessage()
this.compileLatexMessage()
this.minimalInformationMessage()
log.info "Completed at: " + workflow.complete
log.info "Duration : " + workflow.duration
log.info "Success : " + workflow.success
log.info "Exit status : " + workflow.exitStatus
log.info "Error report: " + (workflow.errorReport ?: '-')
}
workflow.onError {
// Display error message
this.nextflowMessage()
this.compileLatexMessage()
log.info "Workflow execution stopped with the following message: " + $workflow.errorMessage
}