What does the symbol ~ do in latex? - latex

This code :
\begin{minipage}{0.4\textwidth}
\begin{flushleft}
\large
\textit{Author}\\
B.J. \textsc{Blazkowicz} % Your name
\end{flushleft}
\end{minipage}
~% THIS IS WHAT I NEED TO KNOW
\begin{minipage}{0.4\textwidth}
\begin{flushright}
\large
\textit{Supervisor}\\
Dr. Caroline \textsc{Becker} % Supervisor's name
\end{flushright}
\end{minipage}
produces
And this code
...
B.J. \textsc{Blazkowicz} % Your name
\end{flushleft}
\end{minipage}
~% THIS IS WHAT I NEED TO KNOW
\begin{minipage}{0.4\textwidth}
\begin{flushright}
\large
...
produces
How does that work? Does it like lock the minipages to the borders?

Related

In latex how to escape "{" in \verb in tabularx environmnet?

I tried \verb|\{|, and it will print \{. If using \verb|{| without the backslash, an error would occur that says ! File ended while scanning \TX#get#body
Use the following to replicate this error on Overleaf or WinEdt:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{ll}
\hline
\verb|{| & Error. \\ % The use of \verb|{| here generates the error!
\hline
\end{tabularx}
\end{table}
\end{document}
I the above code, "\verb|{|" will generate the error.
With the kind help from samcarter_is_at_topanswers.xyz, I understand now that "{" can be displayed in tabularx using \listinline{{}. But this gives a plain-text style "{". Is there a way to make the "{" more code style? See the below picture for comparison.
You can use the listings package:
\documentclass{article}
\usepackage{tabularx}
\usepackage{listings}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{lX}
\hline
\lstinline{\}} & Error. \\
\hline
\end{tabularx}
\end{table}
\end{document}

How it is possible to convert LaTeX document to Word (docx file) with all cross-references and labels for images and equations, tables by Pandoc?

I have a tex-file obtained originally from RStudio with bookdown. The original set of Rmd-files were deleted by accident.
So I need to convert below minimized correct tex-file to Word (docx file extension):
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\#ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Simple document},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if#noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin#nat#width>\linewidth\linewidth\else\Gin#nat#width\fi}
\def\maxheight{\ifdim\Gin#nat#height>\textheight\textheight\else\Gin#nat#height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps#figure{htbp}
\makeatother
\usepackage[normalem]{ulem}
% Avoid problems with \sout in headers with hyperref
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\usepackage[]{biblatex}
\addbibresource{bibliography.bib}
\title{Simple document}
\author{}
\date{\vspace{-2.5em}}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{proposition}{Proposition}[section]
\newtheorem{conjecture}{Conjecture}[section]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\theoremstyle{definition}
\newtheorem{exercise}{Exercise}[section]
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{solution}{Solution}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\hypertarget{format}{%
\section{Format}\label{format}}
Read \ref{format} for details.
Or read \protect\hyperlink{format}{format}.
Formatting:
\begin{itemize}
\tightlist
\item
sup-script or power - x\textsuperscript{2} ;
\item
sub-script - y\textsubscript{3} ;
\item
strike through - \sout{strike through} ;
\item
term -- definition ;
\item
long term --- long definition .
\end{itemize}
Here comes \textbf{footnote} \footnote{Footnote text} with its contents.
Image with caption, see \ref{fig:image}.
\begin{figure}
\centering
\includegraphics{image.png}
\caption{\label{fig:image} Image}
\end{figure}
Labeled table is below, see table \ref{tab:table}.
\begin{longtable}[]{#{}ll#{}}
\caption{\label{tab:table}\\
My table}\tabularnewline
\toprule
\textbf{Col 1 header} & \textbf{Col 2 header} \\
\midrule
\endfirsthead
\endhead
r1c1 & r1c2 \\
r2c1 & r2c2 \\
\bottomrule
\end{longtable}
Inline: \(a^2 + b^2 = c^2\).
Block:
\[ E = \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}} \]
Labeled, see \eqref{eq:eq}:
\begin{equation}
f\left(k\right) =\binom{n}{k} p^k\left(1-p\right)^{n k}
\label{eq:eq}
\end{equation}
See LaTeX \autocite{latex} site for details.
Code is below, see \ref{exm:code}:
\begin{example}
\protect\hypertarget{exm:code}{}{\label{exm:code} }Hello world
\end{example}
\begin{verbatim}
int main(){
return 0;
}
\end{verbatim}
\hypertarget{references}{%
\section*{References}\label{references}}
\addcontentsline{toc}{section}{References}
\printbibliography
\end{document}
When I try to convert it to docx using pandoc (2.16.1 version) command below:
pandoc simple.tex --to docx+native_numbering --output simple.docx --table-of-contents --toc-depth 5 --number-sections --citeproc --verbose --csl ieee.csl
(In the above command ieee.csl was downloaded from Zotero).
I get
and I see many strange things:
[fig:image] along with Figure with number;
[tab:table] along with Table with number;
[eq:eq] instead of equation number;
[exm:code] instead of example number.
Is it possible to replace (or suppress them for Figure and Table) above strange […] fields by correct numbers and links using Pandoc to get correct docx output?
This is currently not supported by plain pandoc, but you can use filters to get the numbering back. E.g., the resolve-references.lua filter in the OpenJournals "Inara" project does something comparable. You may have to adjust and extend it to fully suit your requirements.

suggest the best way to write the code of bellow equation in latex

I tried to write the code of this equation but there are some mistakes, I tried by many ways but could not find the right way, so please help me in this. My code is here.
$|\,\psi(t=0) \,\rangle=\left| \, \psi_{0}\right \rangle \, \stackrel{A: \lambda}{\longrightarrow},| \, \psi \lambda\rangle \, | \, \psi_\lambda \, \rangle \, \longrightarrow \, | \psi(t) \, \rangle = | \, \Tilde{\psi} \, \rangle \,\stackrel{A : \lambda_2}{\nearrow} \,\stackrel{A: \Tilde{\lambda} }{\longrightarrow} \, $
This is my output.
Maybe you want something like this?
The full code, done with 'TikZ':
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{positioning,arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node{$|\psi_{t=0}\rangle=|\psi_{0}\rangle\stackrel{A:\lambda}{\longrightarrow}|\psi_\lambda\rangle\longrightarrow|\psi_t\rangle=|\Tilde{\psi}\rangle\stackrel{A: \Tilde{\lambda} }{\longrightarrow}|\psi_{\Tilde{\lambda}}\rangle$};
\draw[Round Cap-To] (2.25,1em) -- (2.8,2em) node[rotate=35,pos=.5,above,scale=0.7]{$A:\lambda_2$};
\draw (2.8,2em) node[anchor=west] {$|\psi_{\lambda_{2}}\rangle$};
\draw[-To] (0,-0.2) |- (0.5,-4em) node[anchor=west]{$|\psi_{t=\varepsilon}\rangle\stackrel{A:\lambda}{\longrightarrow}|\psi_\lambda\rangle$};
\draw[Round Cap-To] (2.25,-1em) -- (2.8,-2em) node[anchor=west] {$\dots$};
%\draw (0,-2em) node{$\longrightarrow$};
\end{tikzpicture}
\end{document}
You could use the stackengine package:
\documentclass{article}
\usepackage{stackengine}
\begin{document}
\begin{equation}
\stackMath
A
\stackengine{2pt}{
\rightarrow B
}{
\rule[3pt]{.5pt}{1.5ex}\mkern-7mu\rightarrow
C
}{U}{l}{F}{T}{S}
\end{equation}
\end{document}

Algorithm left margin and Comment Customizing

I'm trying to save space, reduce both margins of the algorithm in 1, and add a comment after the "do" in line 1 (see the problem in red). All my tentatives failed. I only could place the comment between the "SemCompositeIndex" and the "do."
Its compilable code follows:
\documentclass{article}
\usepackage{mdframed}
\usepackage[noend,linesnumbered,ruled,vlined]{algorithm2e}
\makeatletter
%Remove right hand margin in algorithm
\patchcmd{\#algocf#start}% <cmd>
{-1.5em}% <search>
{0pt}% <replace>
{}{}% <success><failure>
\makeatother
\begin{document}
\begin{algorithm}
\SetAlgoLined
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\Input{SemCompositeIndex \tcp*[f]{XXX}(a)}
\Output{CSemCompositeIndex \tcp*[f]{YYY}(b)}
\ForEach{entry $\in$ SemCompositeIndex \tcp*[f]{XXX}}{
CSemCompositeIndex.put(entry.compositeKey, compressMatchCounter(entry.matchCounter)) \tcp*[f]{ZZZ}}
\caption{Compress}
\label{alg:compress}
\end{algorithm}
\end{document}
I'm new here. Let me know if I need to put more details!
Thank you so much for your attention and participation.
Happy new year to all of us!
To place a comment after the condition of the for loop, you can use \ForEach(\tcp*[f]{XXX}){...}{....}
\documentclass{article}
\usepackage{mdframed}
\usepackage[noend,linesnumbered,ruled,vlined]{algorithm2e}
\setlength{\algomargin}{15pt} %#Werner Solution for left margin
\makeatletter
%Remove right hand margin in algorithm
\patchcmd{\#algocf#start}% <cmd>
{-1.5em}% <search>
{0pt}% <replace>
{}{}% <success><failure>
\makeatother
\begin{document}
\begin{algorithm}
\SetAlgoLined
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\Input{SemCompositeIndex \tcp*[f]{XXX}(a)}
\Output{CSemCompositeIndex \tcp*[f]{YYY}(b)}
\ForEach(\tcp*[f]{XXX}){entry $\in$ SemCompositeIndex }{
CSemCompositeIndex.put(entry.compositeKey, compressMatchCounter(entry.matchCounter)) \tcp*[f]{ZZZ}}
\caption{Compress}
\label{alg:compress}
\end{algorithm}
\end{document}
This is the default layout of an algorithm when using algorithm2e:
\documentclass{article}
\usepackage[noend,linesnumbered,ruled,vlined]{algorithm2e}
%\setlength{\algomargin}{0pt}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}
You can use \setlength{\algomargin}{<len>} to change the margins. For example, this is what \setlength{\algomargin}{0pt} looks like:
The default (first image above) is \leftskip + \parindent.

How to I center vertically in this code (buisness card)?

How do I vertically center the (web, email, email, mobile) field right to the QR-code?
\documentclass[11pt,a4paper]{memoir}
\setstocksize{55mm}{85mm} % UK Stock size
\setpagecc{55mm}{85mm}{*}
\settypeblocksize{45mm}{75mm}{*}
\setulmargins{5mm}{*}{*}
\setlrmargins{5mm}{*}{*}
\usepackage{xcolor}
\setheadfoot{0.1pt}{0.1pt}
\setheaderspaces{1pt}{*}{*}
\usepackage{fontspec}
\checkandfixthelayout[fixed]
\pagestyle{empty}
\usepackage{pstricks}
\usepackage{auto-pst-pdf,pst-barcode}
\begin{document}
\begin{Spacing}{0.75}%
\noindent
\textbf{Helena Doe}\\
\tiny subtitle \hfill {\color{gray}Division / Employer}\\
\rule{74mm}{.3mm}\\
\begin{minipage}[t]{33mm}
\vspace{-0mm}%
\begin{pspicture}(25mm,25mm)
% The MECARD format is used to exchange contact information. More information at:
% http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/function/application/addressbook/index.html
\psbarcode{MECARD:N:Last name, First Name;URL:https://fqdn;EMAIL:helena#univ.edu;NOTE:GPG: ;;}{eclevel=L width=1 height=1}{qrcode}
\end{pspicture}
\end{minipage}
\hspace{1mm}
\begin{minipage}[t]{42mm}
\vspace{-0mm}%
\begin{flushleft}
{\scriptsize
\begin{Spacing}{1}%
% \textbf{Job Title}\\
% \hspace{5mm}Speciality 1\\
% \hspace{5mm}Speciality 2\\
% \hspace{5mm}Speciality 3 \vspace{2mm}\\
\end{Spacing}
}
{\tiny
\begin{tabular}{rl}
{\color{gray}web} & https://fqdn/\\
{\color{gray}email} & helena#univ.edu\\
{\color{gray}email} & hxr42#gmail.com\\
{\color{gray}mobile} & +1 123 456 7890\\
\end{tabular}
\vspace*{2mm}
}
\end{flushleft}
\end{minipage}
\rule{74mm}{0mm}\\
\texttt{\fontsize{2.84mm}{3.55mm}\selectfont 425B 030A B8D2 0316 CA1B 4709 CA83 5DDA EC31 CA56} % GPG KEY ID
\end{Spacing}
\end{document}
I tried
\vapce*{\fill}
but this does not work. And I tried some other things, which failed all.
Has anybody an idea?
For compelation I u xelatex!
Okay, I need some more details, sorry, but I have said everything about this problem, this is really annoying.
complexinfinity
minipage allows to specify the height with an optional argument. If this option is set, the text can be centred with the c key:
% !TeX TS-program = xelatex
\documentclass[11pt,a4paper]{memoir}
\setstocksize{55mm}{85mm} % UK Stock size
\setpagecc{55mm}{85mm}{*}
\settypeblocksize{45mm}{75mm}{*}
\setulmargins{5mm}{*}{*}
\setlrmargins{5mm}{*}{*}
\usepackage{xcolor}
\setheadfoot{0.1pt}{0.1pt}
\setheaderspaces{1pt}{*}{*}
\usepackage{fontspec}
\checkandfixthelayout[fixed]
\pagestyle{empty}
\usepackage{pstricks}
\usepackage{auto-pst-pdf,pst-barcode}
\begin{document}
\begin{Spacing}{0.75}%
\noindent
\textbf{Helena Doe}\\
\tiny subtitle \hfill {\color{gray}Division / Employer}\\
\rule{74mm}{.3mm}\\
\begin{minipage}[t]{33mm}
\vspace{-0mm}%
\begin{pspicture}(25mm,25mm)
% The MECARD format is used to exchange contact information. More information at:
% http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/function/application/addressbook/index.html
\psbarcode{MECARD:N:Last name, First Name;URL:https://fqdn;EMAIL:helena#univ.edu;NOTE:GPG: ;;}{eclevel=L width=1 height=1}{qrcode}
\end{pspicture}
\end{minipage}
\hspace{1mm}
\begin{minipage}[t][24mm][c]{42mm}
\tiny
\begin{tabular}{rl}
{\color{gray}web} & https://fqdn/\\
{\color{gray}email} & helena#univ.edu\\
{\color{gray}email} & hxr42#gmail.com\\
{\color{gray}mobile} & +1 123 456 7890\\
\end{tabular}
\end{minipage}
\rule{74mm}{0mm}\\
\texttt{\fontsize{2.84mm}{3.55mm}\selectfont 425B 030A B8D2 0316 CA1B 4709 CA83 5DDA EC31 CA56} % GPG KEY ID
\end{Spacing}
\end{document}

Resources