Skip to content

Commit

Permalink
Fix #1860. Accept subdirectories when using subfiles
Browse files Browse the repository at this point in the history
Consider a main.tex including the subfile{extra/section}.

When compiling the section file, the output directory is %OUTDIR%/extra.
  • Loading branch information
jlelong committed Dec 13, 2019
1 parent d2b3db6 commit 9ee65b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class Builder {
//output directory does not exist, the latex commands simply fail.
if (this.extension.manager.rootDir !== undefined) {
const rootDir = this.extension.manager.rootDir
let outDir = this.extension.manager.getOutDir()
let outDir = this.extension.manager.getOutDir(rootFile)
if (!path.isAbsolute(outDir)) {
outDir = path.resolve(this.extension.manager.rootDir, outDir)
}
Expand Down Expand Up @@ -503,7 +503,7 @@ export class Builder {

const doc = rootFile.replace(/\.tex$/, '').split(path.sep).join('/')
const docfile = path.basename(rootFile, '.tex').split(path.sep).join('/')
const outDir = this.extension.manager.getOutDir()
const outDir = this.extension.manager.getOutDir(rootFile)

return arg.replace(/%DOC%/g, docker ? docfile : doc)
.replace(/%DOCFILE%/g, docfile)
Expand Down
11 changes: 10 additions & 1 deletion src/components/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,20 @@ export class Manager {
if (texPath === undefined) {
return './'
}

/* if current file is a localRootFile, then we take the rootFile for computing
placeholders substitution.
We add to outdir the extra directory levels relative to the rootFile. */
let relativePath: string = ''
if (this.localRootFile === texPath && this.rootFile !== undefined) {
relativePath = path.relative(path.dirname(this.rootFile), path.dirname(texPath))
texPath = this.rootFile
}
const doc = texPath.replace(/\.tex$/, '').split(path.sep).join('/')
const docfile = path.basename(texPath, '.tex')
const configuration = vscode.workspace.getConfiguration('latex-workshop')
const docker = configuration.get('docker.enabled')
const out = (configuration.get('latex.outDir') as string)
const out = path.join(configuration.get('latex.outDir') as string, relativePath)
return out.replace(/%DOC%/g, docker ? docfile : doc)
.replace(/%DOCFILE%/g, docfile)
.replace(/%DIR%/g, docker ? './' : path.dirname(texPath).split(path.sep).join('/'))
Expand Down

0 comments on commit 9ee65b7

Please sign in to comment.