The latex package "indentfirst" not working in R-markdown - latex

I am trying to indent the first line after a section header using the indentfirst package but it is not working.
---
title: "Evaluation of Coaching Teachers by Program"
header-includes:
- \usepackage{indentfirst}
- \usepackage{booktabs}
- \usepackage{amsmath}
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
author:
- "Office of Assessment and Accreditation"
- "University of South Carolina"
date: "August 2019"
output: pdf_document
---
\newpage
\blandscape
\section{\textbf{Introduction}}
The purpose of this report is to provide an overview.
\section{\textbf{Overview of all programs}}
\elandscape
Here is the latex output
\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
pdftitle={Evaluation of Coaching Teachers by Program},
pdfauthor={Office of Assessment and Accreditation; University of South Carolina},
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
\usepackage{graphicx,grffile}
\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}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}
%%% Change title format to be more compact
\usepackage{titling}
% Create subtitle command for use in maketitle
\providecommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{Evaluation of Coaching Teachers by Program}
\pretitle{\vspace{\droptitle}\centering\huge}
\posttitle{\par}
\author{Office of Assessment and Accreditation \\ University of South Carolina}
\preauthor{\centering\large\emph}
\postauthor{\par}
\predate{\centering\large\emph}
\postdate{\par}
\date{August 2019}
\usepackage{indentfirst}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{pdflscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}
\begin{document}
\maketitle
\newpage
\blandscape
\section{\textbf{Introduction}}
The purpose of this report is to provide an overview of in
\section{\textbf{Overview of all programs}}
\elandscape
\end{document}
I want the first line after the section header to be indented.

The indentfirst package works, but something added \setlength{\parindent}{0pt} to your code, so the indention of the first paragraph is not visible because it is zero.
To revert this try with
\usepackage{indentfirst}
\setlength{\parindent}{20pt}
in your header includes.

Related

A lot of space at the beginning of the page in Latex

There is a lot of space in the beginning which I do no like. And also to other sections (but only the start page of the section). Do you guys have any clue on how to reduce the vertical space between the header and the actual content.
\documentclass[12pt, a4paper, oneside, openany]{scrbook}
\pagestyle{headings}
%page layout
\setlength{\voffset}{0mm}
\setlength{\topmargin}{0mm}
\setlength{\headsep}{0mm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{0mm}
\setlength{\textheight}{210mm}
\setlength{\textwidth}{150mm}
\setlength{\marginparwidth}{5mm}
\setlength{\marginparsep}{3mm}
\setlength{\marginparpush}{7mm}
\setlength{\parindent}{5mm}
\setlength{\footskip}{0mm}
\usepackage{fontspec}
\fontspec{Times New Roman}
\usepackage{url}
\linespread{1.5}
\usepackage[acronym]{glossaries}
\parindent 10mm
\parskip 5mm
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage[a4paper]{geometry}
You can redeclare the sectioning command which you'd like to change and set whatever beforeskip you like:
% !TeX TS-program = lualatex
\documentclass[12pt, a4paper, oneside, openany]{scrbook}
\pagestyle{headings}
\RedeclareSectionCommand[beforeskip=0pt]{chapter}
%page layout
\setlength{\voffset}{0mm}
\setlength{\topmargin}{0mm}
\setlength{\headsep}{0mm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{0mm}
\setlength{\textheight}{210mm}
\setlength{\textwidth}{150mm}
\setlength{\marginparwidth}{5mm}
\setlength{\marginparsep}{3mm}
\setlength{\marginparpush}{7mm}
\setlength{\parindent}{5mm}
\setlength{\footskip}{0mm}
\usepackage{fontspec}
\fontspec{Times New Roman}
\usepackage{url}
\linespread{1.5}
\usepackage[acronym]{glossaries}
\parindent 10mm
\parskip 5mm
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage[a4paper]{geometry}
\begin{document}
\chapter{title}
\end{document}
Answer courtesy of https://tex.stackexchange.com/questions/62125/how-to-remove-top-margin-above-tableofcontents. Visit this excellent post to get a comprehensive explanation and alternative methods to do your stuff.
Add the following to your preamble:
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{\begingroup%
\patchcmd{\#makeschapterhead}% <cmd>
{\vspace*{50\p#}}% <search>
{}% <replace>
{}{}% <success><failure>
\oldtableofcontents%
\endgroup%
}
\makeatother
The above does a local search-and-replace within #makeschapterhead (replacing \vspace*{50\p#} with nothing, before calling the regular table of contents. The redefinition (search-and-replace) is localized within the scope of the group.

Latex: fail to show line breaks in formula with ```\\```

I'm using rmarkdown to knit to pdf. However, line break \\ doesn't take effect. I suspect something is wrong with my package amsmath, because running the tex file also shows the same problem. But I don't know how to fix it.
(I installed R and Rstudio with tinytex, then installed tex live 2021. I don't know whether this can be the cause.)
The code is shown below:
---
title: "test"
date: '2022-04-07'
output:
word_document: default
pdf_document:
keep_tex: yes
---
$$
a = b \\
c = d
$$
Also, when I try knit to word, there are warning messages
[WARNING] Could not convert TeX math
a = b \
c = d
, rendering as TeX:
a = b \
^
unexpected control sequence \
expecting "%", "\label", "\tag", "\nonumber" or whitespace
Building the tex file, I still cannot see the expected linebreak in the output pdf. The tex file is shown below.
% 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={test},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\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
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\title{test}
\author{}
\date{\vspace{-2.5em}2022-04-07}
\begin{document}
\maketitle
\[
a = b \\
c = d
\]
\end{document}
I think this should perfectly answer your question:
https://tex.stackexchange.com/questions/46189/how-do-i-add-a-line-break-in-display-math-mode
In short: \[ \] is made for one equation/one line of math. To add a line-break, you should use an environment like gather or align. The code for align would look like this in your tex-code:
\begin{align}
a &= b \\
c &= d
\end{align}
If you don't need numbering of your equations, you would use the starred version of the respective environment (gather*, align*. Like this:
\begin{align*}
a &= b \\
c &= d
\end{align*}
If the link I provided does not fit your problem, please explain why. I am happy to correct this answer.

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.

Lyx modifying moderncv empty space

I am new on latex and lyx. I have to realize a resume and used moderncv. Do you know how I can have the space behing my picture being reduced ? (The one hatched in red) . As everything is supposed to fit in one page with a cv, it is important for me.
Thanks for your help
%% LyX 2.3.3 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{float}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{xmpmulti}
\usepackage{enumitem}
\moderncvtheme[grey]{classic}
\firstname{John}
\familyname{Do}
\title{Title}
\address{adress}{city}
\mobile{+33 6 §§ §§ §§ §§}
\email{john.do#ens.psl.eu}
\photo[100pt]{Mii_Artwork.png}
\makeatother
\usepackage{babel}
\begin{document}
\maketitle
\section{Formation}
\cventry{2021/2022}{Master de Science cognitive}{Ecole normale supérieure rue d'Ulm}{Paris}{France}{}
\end{document}
Quick hack: add \vspace{-1.5cm} after \maketitle :
`
%% LyX 2.3.3 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{float}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{xmpmulti}
\usepackage{enumitem}
\moderncvtheme[grey]{classic}
\firstname{John}
\familyname{Do}
\title{Title}
\address{adress}{city}
\mobile{+33 6 §§ §§ §§ §§}
\email{john.do#ens.psl.eu}
\photo[100pt]{example-image}
\makeatother
\usepackage{babel}
\begin{document}
\maketitle
\vspace{-1.5cm}
\section{Formation}
\cventry{2021/2022}{Master de Science cognitive}{Ecole normale supérieure rue d'Ulm}{Paris}{France}{}
\end{document}

Latex - \addsec and headsepline

When I write \addsec{Acronymes}, LaTeX puts it in the Table of Contents and DOES the headsepline section. When I write \addsec*{Acronymes}, LaTeX doesnt put it in the Table of Contents and doesnt write it in the headsepline section. But I want that it doesnt appears in the Table of Contents and does appear in the headsepline.
So how do it?
Thats what I've done for this:
\documentclass[a4paper, 12pt, german, headsepline, footsepline, listtotoc, bibtotoc] {scrartcl}
\bibliographystyle{annotate}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ansinew]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[printonlyused]{acronym}
%head and footsepline
\usepackage[headsepline,plainheadsepline]{scrpage2}
\clearscrheadfoot
\pagestyle{scrheadings}
\automark[subsection]{section}
\ihead{my title}
\ohead{\headmark}
\ifoot{my name}
\ofoot{\pagemark}
\usepackage{hyperref}
\hypersetup{
colorlinks,
citecolor=blue,
filecolor=blue,
linkcolor=blue,
urlcolor=blue
}
\begin{document}
\input{include/Abstract}
\newpage
\tableofcontents
\newpage
\listoffigures
\newpage
\listoftables
\newpage
\addsec*{Acronymes}
%\addsec{Acronymes}
\begin{acronym}
\acro{HTTP}{Hypertext Transfer Protocol}
\end{acronym}
\end{document}
You can momentarily remove the functionality of \addcontentsline - the macro in charge of adding elements to the ToC - using
{% \begingroup
\renewcommand{\addcontentsline}[3]{}% Remove functionality of \addcontentsline
\addsec{Acronymes}%
}% \endgroup
Grouping via { and } ensure that the command redefinitions are restored after the group ends.

Resources