I have to write an article with many blocks embedding equations and the output from R. I've decided to use the package minted for everything as the best option to avoid complex formating.
I've also defined general spacing and font sizes.
\RequirePackage{luatex85}
\documentclass[11pt, a4paper, spanish]{article}
\usepackage[left=3.5cm, right=3.4cm, top=4.7cm, bottom=4.1cm]{geometry}
\renewcommand{\baselinestretch}{1.54}
\usepackage{parskip} % separación entre parrafos
\parskip=12pt
\setlength{\parindent}{2em}
\usepackage{polyglossia}
\setmainlanguage{spanish}
\usepackage[no-math]{fontspec}
\setmainfont{TeXGyrePagellaX}
\usepackage{float}
\usepackage{minted}
\usepackage{indentfirst}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{bg}{rgb}{0.92,0.97,1}
\begin{document}
\section{First}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\begin{minted}[fontsize=\small, bgcolor=bg]{text}
E=m·c^2
some code
\end{minted}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\begin{minted}[fontsize=\small, bgcolor=bg, escapeinside=||, mathescape=true]{text}
|$E=m·c^2$|
\end{minted}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{document}
The result looks like this:
It seems OK, but how can I change the line spacing before and after the minted text? I would like to have two kind of minted text on my article, one like it is now, independent paragraphs, but another kind with simple spacingtimgur.
How can I get in my example simple line spacing, as if it was all the same paragraph?
I need to write many equations and small minted code but I don't want to waste much space.
I prefer a simple solution, sort of command to remove previous space instead of large macro definitions.
I would also like to know how to keep the previous text and the minted block together on the same page if there is a pagebreak. Otherwise latex mixes large tables and figures and is difficult to keep track of things.
PS: I have created a new related question: How to reduce the space before and after minted text with captions (listing)? where I'm asking how to reduce the margins when using captions, within a listing environment.



\parskipto 12pt,\parindentto 2em and\baselinestretchto 1.54? Isn't it too much? I can understand you need “doublespacing”, but then why adding a nonzero parskip? – egreg Jul 26 '19 at 22:36