I'm using django built-in templates tags which are {% load static %} {% extends 'base.html' %} etc. so whenever I'm saving my document by pressing ctrl+s the formatting which should be gets disturbed which causes errors:
Unclosed tag on line 1: 'block'. Looking for one of: endblock.
before saving the document the editor looks something like this:
but as soon as I save my document it becomes like this which results in the above mentioned error
any solution for that? maybe add or remove some formatting extensions?
Okay so I tweaked around some settings.json in vscode and found my solution:
add the following lines
"[django-html]": {
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
},
"editor.defaultFormatter": "batisteo.vscode-django"
},
My assumption to this solution is that, earlier this [django-html] settings was not instantiated so by default a django-html template was getting formatted through [html] settings as seen in the image below (pls correct me if my assumption is wrong).
I am using bookdown for a documentation which is outputted with bookdown::gitbook and bookdown::pdf_book.
In my Rmd files, I am using a div to wrap around notes and warnings styled with a css file. For example:
<div class="note">
This is a note.
</div>
Obviously, HTML and CSS is ignored when generating the PDF file. I was wondering if there is a way to "inject" a small script that would replace the div with, for example, a simple prefix text.
Or, is there another way to have it formatted in HTML and in the PDF without littering my file by adding something lengthy every time like:
if (knitr::is_html_output(excludes='epub')) {
cat('
<div class="note">
This is a note.
</div>
')
} else {
cat('Note: This is a note.')
}
I could also style blockquotes as described here but it is not an option as I still need blockquotes.
The appropriate way to do this is to use a fenced div rather than inserting HTML directly into your markdown and trying to parse it later with LUA. Pandoc already allows you to insert custom styles and process them to both file types. In other words, it will take care of creating the appropriate HTML and LaTeX for you, and then you just need to style each of them. The Bookdown documentation references this here, but it simply points to further documentation here, and here.
This method will create both your custom classed div in html and apply the same style name in the LaTeX code.
So, for your example, it would look like this:
::: {.note data-latex=""}
This is a note.
:::
The output in HTML will be identical to yours:
<div class="note">
<p>This is a note.</p>
</div>
And you've already got the CSS you want to style that.
The LaTeX code will be as follows:
\begin{note}
This is a note.
\end{note}
To style that you'll need to add some code to your preamble.tex file, which you've already figured out as well. Here's a very simple example of some LaTeX that would simply indent the text from both the left and right sides:
\newenvironment{note}[0]{\par\leftskip=2em\rightskip=2em}{\par\medskip}
I found this answer on tex.stackexchange.com which brought me on the right track to solve my problem.
Here is what I am doing.
Create boxes.lua with following function:
function Div(element)
-- function based on https://tex.stackexchange.com/a/526036
if
element.classes[1] == "note"
or element.classes[1] == "side-note"
or element.classes[1] == "warning"
or element.classes[1] == "info"
or element.classes[1] == "reading"
or element.classes[1] == "exercise"
then
-- get latex environment name from class name
div = element.classes[1]:gsub("-", " ")
div = div:gsub("(%l)(%w*)", function(a, b) return string.upper(a)..b end)
div = "Div"..div:gsub(" ", "")
-- insert element in front
table.insert(
element.content, 1,
pandoc.RawBlock("latex", "\\begin{"..div.."}"))
-- insert element at the back
table.insert(
element.content,
pandoc.RawBlock("latex", "\\end{"..div.."}"))
end
return element
end
Add pandoc_args to _output.yml:
bookdown::pdf_book:
includes:
in_header: latex/preamble.tex
pandoc_args:
- --lua-filter=latex/boxes.lua
extra_dependencies: ["float"]
Create environments in preamble.tex (which is also configured in _output.yml):
I am using tcolorbox instead of mdframed
\usepackage{xcolor}
\usepackage{tcolorbox}
\definecolor{notecolor}{RGB}{253, 196, 0}
\definecolor{warncolor}{RGB}{253, 70, 0}
\definecolor{infocolor}{RGB}{0, 183, 253}
\definecolor{readcolor}{RGB}{106, 50, 253}
\definecolor{taskcolor}{RGB}{128, 252, 219}
\newtcolorbox{DivNote}{colback=notecolor!5!white,colframe=notecolor!75!black}
\newtcolorbox{DivSideNote}{colback=notecolor!5!white,colframe=notecolor!75!black}
\newtcolorbox{DivWarning}{colback=warncolor!5!white,colframe=warncolor!75!black}
\newtcolorbox{DivInfo}{colback=infocolor!5!white,colframe=infocolor!75!black}
\newtcolorbox{DivReading}{colback=readcolor!5!white,colframe=readcolor!75!black}
\newtcolorbox{DivExercise}{colback=taskcolor!5!white,colframe=taskcolor!75!black}
Because I have also images and tables within the boxes, I run into LaTeX Error: Not in outer par mode.. I was able to solve this issue by adding following command to my Rmd file:
```{r, echo = F}
knitr::opts_chunk$set(fig.pos = "H", out.extra = "")
```
I am looking to generate a string like \usepackage{mypackage} from a Django template.
Suppose there is a variable package.name in the context how can I generate this?
Firstly I tried, \usepackage{{{package.name}}} but that throws TemplateSyntaxError
Then I tried \usepackage{ {{package.name}} } which works but has the two spaces in the output, ie, \usepackage{ mypackage }
Is there an easy way to generate this string with Django template engine?
You can also print strings with the mustache-syntax e.g.: {{ 'random string' }}. So we can print the corresponding curly brace like this:
\usepackage{{ '{' }}{{ package.name }}{{ '}' }}
Output:
\usepackage{mypackage}
You can do something like this using span
\usepackage{<span>{{package.name}}</span>}
one option is that you can write a template tag that will render it as you want and give the package name as a variable
I am not sure what is wrong with the following yaml
ansible -v local -c local -i ../../../inventory/staging.yml -m template -a "src=hamap.1.j2 dest=/tmp/tmp.txt" --extra-vars=#./vars.1.yaml
I am expecting a file /tmp/tmp.txt to be generated.
I get the following error
ERROR! Invalid extra vars data supplied. '#./vars.1.yaml' could not be made into a dictionary
I tried the following in the ansible test site
It gives me a similar error message
Error! ERROR! Invalid extra vars data supplied. '#variables.yml' could not be made into a dictionary
./vars.1.yaml
---
- Somevar:
- somesubvar:
- somevalue
hamap.1.j2
{% for somesubvar in Somevar %}
{{ somesubvar }} # somevalue should come out here
{% endfor %}
Using the following site and starting off really simply.
I was able to identify my problem. - indicates a sub value.
The documents from ansible
YAML Basics
For Ansible, nearly every YAML file starts with a list. Each item in the list is a list of key/value pairs, commonly called a “hash” or a “dictionary”. So, we need to know how to write lists and dictionaries in YAML.
Esentailly I was trying to put a dictionary value - Somevar at the top of the yaml file structure. Which is expecting a simple list element. No - in front of it.
The following works in the test site.
https://ansible.sivel.net/test/
./vars.1.yaml
---
Somevar:
- somesubvar:
- somevalue
hamap.1.j2
{% for somesubvar in Somevar %}
{ somesubvar } # somevalue should come out here
{% endfor %}
I'm trying to makemessages on a template that has a translation which contains a modulo, like this;
{% trans "100% escaping problems sucks" %}
But I get this error:
Error: errors happened while running xgettext on site.html
./templates/site.html.py:34: warning: 'msgid' format string with unnamed
arguments cannot be properly localized:
The translator cannot reorder the arguments.
Please consider using a format string with named arguments,
and a mapping instead of a tuple for the arguments.
And if I try to escape it like this;
{% trans "100%% escaping problems sucks" %}
I get this error;
Error: errors happened while running xgettext on site.html.py
xgettext: error while opening "./templates/site.html.py" for
reading: No such file or directory
I have no idea why it is looking for ./templates/site.html.py .. it should be ./templates/site.html
Any idea ?
Edit: I forgot the Django version, it's 1.2.0 beta1
As per this ticket you might try upgrading to at least 1.2.1...