My current config is the following:
"latex-workshop.latex.tools": [{
"name": "texify",
"command": "texify",
"args": [
"--synctex",
"--pdf",
"--tex-option=\"-interaction=nonstopmode\"",
"--tex-option=\"-file-line-error\"",
"%DOC%.tex"
],
"env": {}
}
]
However, I am trying to put all the files that are generated, which aren't the output pdf (so .aux and .log for now), somewhere else so it doesn't fill up everything. I don't care if it's a subfolder, or one folder for all project. How can I do this?
You probably moved on from your question but for others with this question, I have found the answer here:
https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-tools
Basically, add this to your settings.json:
"latex-workshop.latex.outDir": "<Name of your output dir>"
(Note: It will include the .pdf file there too)
Related
In order to define my environment variables in a single place a configured a task in which a run a shell script. The task is run as preLaunchTask in my launch.json.
In my launch.json I now try to reference the environment variables I configured in the script (like export AWS_REGION="eu-west-1").
The launch.json looks as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
//..
"env": {
//"AWS_REGION": "us-east-1", //works
"AWS_REGION": "${env:AWS_REGION}", //doesn't work, why?
},
"args": [],
"preLaunchTask": "setupEnv",
}
] }
Doesn't work, why?
According to this post from user weinand...
The ".env" file is read and processed after VS Code has substituted
variables in the launch config. So your debugged program will indeed
see the environment variable "FOO" with the correct value but VS
Code's variable substitution in the launch.json will not see it.
The reason for this is that ".env" files are a node.js concept and not
a generic platform mechanism. So VS Code does not know anything about
.env files, but the node.js debugger knows about .env files.
... this functionality in launch.json is specific for applications running on Node.js, although that's not what M$ explains in their documentations for VSCode.
Possible solution
For Python applications (possibly for other platforms as well) environment variables defined in a .env file (or whatever name you like) will be available for your application as long as the following configuration is present in launch.json...
{
"version": "0.2.0",
"configurations": [
{
[...]
"envFile": "${workspaceFolder}/.env", // Path to the ".env" file.
[...]
}
]
}
Note that just exporting a variable...
export SOMEVAR_A=1234
... will not make the environment variable SOMEVAR_A available for the application being executed by the VSCode debugger nor for the settings - especially inside "env" and "args" ("configurations") - in launch.json as, for example, in this case...
{
"version": "0.2.0",
"configurations": [
{
[...]
"env": {
"SOMEVAR_A": "${env:SOMEVAR_A}"
},
"args": [
"${env:SOMEVAR_A}"
]
[...]
}
]
}
NOTE: In our tests the ${env:SOMEVAR_A} syntax did not work in any scenario. That is, didn't work for the application ("env") and didn't work for the settings ("args") in launch.json.
PLUS I: Dirt Hack
For values present in "args" ("configurations") you can use the hack below...
{
"version": "0.2.0",
"configurations": [
{
[...]
"envFile": "${workspaceFolder}/.env",
"args": [
"`source \"${workspaceFolder}/.env\";echo ${SOMEVAR_A}`"
]
[...]
}
]
}
... as the configuration in "envFile" doesn't work.
Notice, although, that the following construction...
[...]
"args": [
"`echo ${SOMEVAR_A}`"
]
[...]
... would also work for "args" as long as the environment variable "SOMEVAR_A" has been previously exported in the conventional way.
The same reasoning would work for a tasks (tasks.json), but in both cases we can't guarantee that.
TIP: An .env File Example
SOMEVAR_A="abcd"
SOMEVAR_B="efgh"
SOMEVAR_C=123456
PLUS II: Export Variables
There are cases where you will need to export variables (eg. export SOMEVAR_A="abcd") so that they can be consumed by certain resources. In these cases there may be problems, because the fact that we export variables prevents (we don't know why) that they are seen in the context of the "envFile" configuration "envFile": "${workspaceFolder}/.env".
A workaround to get around these limitations is to add set -a before the variables set and set +a after it. With this we were able to meet the two scenarios as this example...
#!/usr/bin/env bash
set -a
SOMEVAR_A="abcd"
SOMEVAR_B="efgh"
SOMEVAR_C=123456
set +a
... or in a more compatible and safe way use set -a/set +a as in this example...
[...]
"args": [
"`set -a;source \"${workspaceFolder}/.env\";set +a;echo ${SOMEVAR_A}`"
[...]
VSCode's support for environment variables is a mess! 🙄
Conclusion
We don't know if the limitations we are dealing with here are from VSCode's own design or are bugs. Anyway, it doesn't seem to make much sense.
These procedures were tested on Manjaro Linux (Arch based).
Thanks! 🤗
[Ref(s).: https://unix.stackexchange.com/a/79077/61742 , https://stackoverflow.com/a/30969768/3223785 ]
Looking at the issue comment quoted below, it seems this is currently not possible.
${env:...} only expands environment variables that were set in the parent shell that ran code. It doesn't expand variables set in the tasks.json env options.
https://github.com/Microsoft/vscode/issues/47985#issuecomment-460678885
It doesn't work as Eduardo Lucio stated. Here is some alternative that works at least on my case that sometimes uses env.sh file to load the environment variables and require .env file for VsCode debugging in Go project. To launch the application normally, load the env using commmand $ source env.sh. On this case, you want to load .env file instead.
Env-Example: Linux/WSL2
If the .sh is what I tought of, probably just some line of export commands: env.sh
export DBUrl="sql-connection-string-here"
export DBPass="somedbpass"
Create the prelaunch task to generate the .env file .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "buildenv",
"command": "sed",
"args": ["s/export //g", "local_env.sh", ">", ".env"],
"type": "shell"
}
]
}
you can see that it calls sed to replace any export with empty string and rewrites a .env file.
On .vscode/launch.json, load the preLaunchTask and change the target envFile to the generated file:
{
"version": "0.2.0",
"configurations": [
{
"name": "My App Debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"preLaunchTask": "buildenv",
"envFile": "${workspaceFolder}/.env",
}
]
}
Now, everytime VsCode run the debugger, it generates .env file and only need to maintain single env.sh file.
Reference: https://stackoverflow.com/a/38746951/12325366
I have a template, which defines all the typesetting recommendations for thesis, but it uses xelatex for compilation. I want to continue using VS Code with Latex Workshops, question is how to change compiler to xelatex from pdflatex. The last one cause next error log:
C:\Users\User\AppData\Local\Programs\MiKTeX 2.9\tex/latex/fontspec\fontspec.sty:45: Fatal Package fontspec Error: The
fontspec package requires either XeTeX or
(fontspec) LuaTeX.
(fontspec)
(fontspec) You must change your typesetting engine to,
(fontspec) e.g., "xelatex" or "lualatex"instead of
(fontspec) "latex" or "pdflatex".
The simplest solution found in issues here, but in more common formulation:
Copying the content, simply go to Preferences → Extensions → LaTeX (meaning LaTeX is LaTeX workshops), find gear-wheel button with name Manage, then find in the list link to settings.json under any tag, open and type next:
"latex-workshop.latex.tools": [{
"name": "latexmk",
"command": "latexmk",
"args": [
"-xelatex",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}],
Reloading the VSCode may be needed.
Also setting.json file could be found in C:\Users\*\AppData\Roaming\Code\User\settings.json.
Use magic comments
add the following line to the beginning of your document.
% !TEX program = xelatex
To enable magic comments, change the setting forceRecipeUsage to false.
I kept getting errors with the other solutions, apparently because I was using backend=biber in my latex code. The following configuration assumes a current MiKTeX setup (including biber) and fixes those problems (also, this does not rely on latexmk). The config uses some inspiration from that of TeXworks.
Inside latex-workshop.latex.tools
{
"name": "xelatex",
"command": "xetex",
"args": [
"-undump=xelatex",
"%DOC%.tex"
],
"env": {}
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOC%"
],
"env": {}
}
Then inside latex-workshop.latex.recipes add the recipe:
{
"name": "xelatex âžž biber âžž xelatex x 2x",
"tools": [
"xelatex",
"biber",
"xelatex",
"xelatex"
]
}
Happy texing!
With the right debug config file I can make VSCode run the currently focussed file through Mocha. However, I find it frustrating that if I am working on the actual code, rather than the spec file and I press F5, it tries to run the actual code as a spec file through Mocha.
So, my question is; given a file structure like this:
Folder
File.js
File.spec.js
And a debug config (.vscode/launch.json) like this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Unit Tests: Current File",
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}",
"args": [
"-u", "tdd",
"--timeout=999999",
"--colors",
"--opts", "${workspaceRoot}/mocha.opts",
"${file}" // I want to make this dynamic
],
}
]
}
Is it possible to get VSCode to debug the spec file whether the spec file (File.spec.js) or it's subject (File.js) are selected?
You can introduce a new dynamic variable by writing a simple extension that just defines one command, e.g. a smartFile command.
Then you can refer to that command in your launch config as ${command:smartFile}.
For the implementation of the command you can use everything available in VS Code extension API. So you can not only calculate a path based on your folder structure, but you can even pop-up UI. E.g. you could use QuickPick to select a test case from the list of all tests.
I want to create a task in Visual Studio Code, but I need a path to the actual file. Is there some option?
My task:
{
"version": "0.1.0",
"command": "${workspaceRoot}/run.sh",
"isShellCommand": true,
"options": {
"cwd": "${hereINeedPathToActualFile}"
},
"args": ["${file}"],
"showOutput": "always"
}
window.title is the setting that worked for me in User Settings:
"window.title": "${activeEditorMedium}"
Other options:
// Controls the window title based on the active editor. Variables are substituted based on the context:
// ${activeEditorShort}: e.g. myFile.txt
// ${activeEditorMedium}: e.g. myFolder/myFile.txt
// ${activeEditorLong}: e.g. /Users/Development/myProject/myFolder/myFile.txt
// ${rootName}: e.g. myProject
// ${rootPath}: e.g. /Users/Development/myProject
// ${appName}: e.g. VS Code
// ${dirty}: a dirty indicator if the active editor is dirty
// ${separator}: a conditional separator (" - ") that only shows when surrounded by variables with values
"window.title": "${activeEditorShort}${separator}${rootName}",
Go to Settings. Inside UserSettings, add this line to the JSON blob:
"window.title": "${activeEditorLong}"
This issue has been addressed several months ago:
Display the full workspace path in UI #3119
There is a new setting window.showFullPath that once enabled will show the full path to the currently opened file instead of the workspace relative path.
The feature is planned to ship in the November release, currently in testing. Then you could control it with window.showFullPath in your configuration file.
UPDATE:
The setting has been changed since I posted the original answer. It's now called window.title, which you could customize whatever you like.
If you need to access a file, you could derive its location from the workspace root:
"filelocation": "${workspaceRoot}/.vscode/tasks.json",
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
I used the following in my "launch.json" file to set the current working directory (cwd) prior to launching a Python program:
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"stopOnEntry": false,
"console": "integratedTerminal"
},
So the path to the actual file's directory is in ${fileDirname}.
I don't use ${workspaceRoot}, because it's deprecated and it is the path to the root of the work space, not the current working directory if the current working directory is a folder other than the root.
There is a list of all of the Visual Studio Code Task variables in Variables Reference.
For the purposes of syntax highlighting and colouring and intellisense is it possible to treat other extensions (tpl, master, etc) as HTML?
I know it's possible on a file by file basis by pressing CTRL+SHIFT+P and selecting "Change Language Mode" BUT I want it to work off file extension, and not have to redo it every time I open a new file.
I also know it's possible for some languages by editing the json files in the plugins directory, BUT there doesn't seem to be one for HTML.
Update for VS Code 1.0:
There is a setting files.associations that can be used to assign file patterns to languages. For example:
"files.associations": {
"*.tpl": "html",
"*.master": "html"
}
Previous answer:
This is a commonly asked feature request and we are looking into this issue for the future.
As a workaround if you need to have a solutio now:
close VS Code
open C:\Users\<your name>\AppData\Local\Code\app-<latest-version>\resources\app\server\lib\mime.js
find the object literal knownTextMimes
for the file extension you want add the proper mime type
for example '.tpl': 'text/html'
save and restart code
Note: this change will not survive automatic updates but the hopes are that there is a better solution in the future update :)
(Tested on version 1.59.1)
It is also possible to set Associations through GUI:
Go to Settings->Text Editor->Files->Associations.
Set Item (file extension) and Value (language).
Open notepad as admin (just in case) by right clicking run as admin.
Click file => open => copy and paste C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\html in box.
select view all file types at bottom right.
Open package.json
Copy and paste
{
"name": "html",
"version": "0.1.0",
"publisher": "vscode",
"engines": { "vscode": "*" },
"extensionDependencies": [
"html"
],
"contributes": {
"languages": [{
"id": "html",
"aliases": ["pd"],
"extensions": [".pd"]
}]
}
}
replace everything with that.
save and quit
restart vs code.
I resolve the issue for my with installing Smarty Extension 1.1.1 + adding this settings into Settings.json
"files.associations": {
"*.tpl": "smarty",
"*.master": "smarty"
}
Jesse's answer is correct. I don't have enough reputation points to comment on his answer, but the path for Mac users is:
cd /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/extensions/html/
Note that there will already be some extensions so instead of copying and pasting the code snippets wholesale, simply add the extension you'd like to the extensions and aliases array like so:
{
"name": "html",
"version": "0.1.0",
"publisher": "vscode",
"engines": { "vscode": "*" },
"contributes": {
"languages": [{
"id": "html",
"extensions": [ ".html", ".htm", ".shtml", ".mdoc", ".jsp", ".asp", ".aspx", ".jshtm", ".ejs" ],
"aliases": [ "HTML", "htm", "html", "xhtml", "ejs" ],
"mimetypes": ["text/html", "text/x-jshtm", "text/template", "text/ng-template"]
}],
"grammars": [{
/* "language": "html", not yet enabled*/
"scopeName": "text.html.basic",
"path": "./syntaxes/HTML.plist"
}]
},
"extensionDependencies": [
"html"
]
}