Double hyphens in lstlisting - latex

I am using lstlisting command in Latex. I want to use double hyphens "--help", but latex hyphens connects like in normal text (but it is source code) and I can't use "-{}-" for separation.
\begin{lstlisting}
$ oc <command> --help
\end{lstlisting}
Could you help me please?
Thanks

Seeing as you're using a terminal-like code display, consider using a \ttfamily as your basicstyle:
\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
\begin{lstlisting}
$ oc <command> --help
\end{lstlisting}
\end{document}

Related

Converting from latex to markdown with pandoc, images not converted

I'm trying to convert a latex file to markdown using Pandoc. The latex file contains linked images, for example like this:
\begin{figure}[htbp]
\begin{center}
\leavevmode
\scalebox{0.4}{\includegraphics{microsatsFigures/Figure_traceView.png}}
\end{center}
\caption{The Traces view}
\label{traces}
\end{figure}
However in the markdown file all I get is
::: center
:::
Is this a known limitation of Pandoc, or is there some command I'm missing that will convert the image instructions? The command I used in pandoc was just the standard format:
pandoc -f latex -t markdown Inputfile.tex -o Outputfile.md

\maketitle in LaTeX gives error "! Missing $ inserted.<inserted text>$ \maketitle". What's the reason?

Here's the simplest LaTeX file:
\documentclass[12pt]{article}
\title{How to write a report in LaTeX}
\author{ABC\\abc_z#yahoo.com}
\date{May 2021}
\begin{document}
\maketitle
Hello World
\end{document}
But when I Quick Build then it gives the following ERRORS:
! Missing $ inserted.<inserted text>$ \maketitle
! Extra }, or forgotten $.<template> \unskip \hfil }\hskip \tabcolsep \endtemplate \maketitle
! Missing $ inserted.<inserted text>$ \maketitle
! Missing } inserted.<inserted text>} \maketitle
I got it. I have used _ , with that it gives error. One needs to either remove _ or use \ with, as \_ , then it works.

Setting otherlangs from the command line using pandoc

Using pandoc, I managed to produce the following output using the YAML prolog.
---
lang: fr
otherlangs: [en]
---
Generates this latex code.
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[shorthands=off,english,main=french]{babel}
\else
\usepackage{polyglossia}
\setmainlanguage[]{french}
\setotherlanguage[]{english}
\fi
But, I cannot manage to have it working using the commande-line arguments. This what I tried.
$ pandoc -s -t latex -V lang=fr -V otherlangs="[en]"
Which produces:
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[shorthands=off,main=french]{babel}
\else
\usepackage{polyglossia}
\setmainlanguage[]{french}
\fi
Any hints on how I should pass de otherlangs variable from the command line?
AFAIK this is not possible since the -M option (and probably -V as well) parse values
as YAML boolean or string values
and otherlangs needs to be a list. What's your use case?
You shouldn't have to set otherlangs manually as it's extracted from spans and divs with the lang attribute (see the MANUAL), for example:
my [english words]{lang=en} inside a span
::: {lang=en}
followed by a native div (using this syntax since pandoc 2.0)
with another paragraph
:::
If you absolutely must set this info from the command-line, using a custom LaTeX template that contains, say, the following (if you're using Polyglossia/XeLaTeX):
\setotherlanguage[]{$myOtherLangs$}
and calling it with pandoc -V myOtherLangs="english,french" should solve your use-case.

How to make sphinx document via pdflatex \raggedright?

How can I render reST document with \raggedright command applied to all the text if I use pdflatex?
Use a custom template.
In the following example, I'll be using xelatex. I would copy the default template for xelatex from /usr/local/lib/python2.7/site-packages/docutils/writers/latex2e/xelatex.tex to a file called mytemplate.tex
The default template looks like this:
$head_prefix% generated by Docutils <http://docutils.sourceforge.net/>
% rubber: set program xelatex
\usepackage{fixltx2e}
\usepackage{fontspec}
% \defaultfontfeatures{Scale=MatchLowercase}
$requirements
%%% Custom LaTeX preamble
$latex_preamble
%%% User specified packages and stylesheets
$stylesheet
%%% Fallback definitions for Docutils-specific commands
$fallbacks$pdfsetup
$titledata
%%% Body
\begin{document}
$body_pre_docinfo$docinfo$dedication$abstract$body
\end{document}
You could add \raggedright just after \begin{document}.
For rendering the document, I'd use the following commands:
rst2xetex --template=mytemplate.tex --use-latex-docinfo mydoc.rst
xelatex mydoc.tex
xelatex mydoc.tex
rm -f *.out *.aux *.log mydoc.tex
(This is on a UNIX-like operating system.)

UTF-8 error in pandoc

I have a markdown + latex document that has compiled fine, until now when I added a special character ('รค') and get the error:
hGetContents: invalid argument (invalid UTF-8 byte sequence)
Following some advice I've found I have tried combinations of these in a custom preamble, but with no success:
\usepackage[utf8]{inputenc} % also tried [utf8x]
\usepackage[T1]{fontenc}
\usepackage[swedish]{babel}
Any suggestions on how to solve this?
The full preamble is:
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,tmargin=2.5cm,bmargin=2.8cm,lmargin=3.5cm,rmargin=3.5cm]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{fixltx2e}
\usepackage[all,error]{onlyamsmath}
\MakeRobust{\overrightarrow}
\usepackage{natbib}
\renewcommand{\normalsize}{\fontsize{11pt}{13.3pt}\selectfont}
pandoc call:
pandoc -f markdown file.mkd -H standard.tex --csl=amnat.csl --bibliography refs.bib -o output.pdf

Resources