I'd like to set up my paragraphs to hang only on the second line. The hanging environment will hang after a particular line, but not on a specific line.
To piggyback off of another question LaTeX: indent from second line, I want it to produce something like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent
sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam
interdum dictum suscipit magna molestie. Vestibulum nibh dolor,
interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem
sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper
in commodo erat dignissim. Cras et suscipit enim.
Nunc adipiscing ligula at ligula egestas id ullamcorper felis luctus.
Aliquam tincidunt turpis sed eros pellentesque iaculis. Nulla
imperdiet cursus enim condimentum congue.
It would also be nice if this could be a set document wide instead of just an environment, but not necessary.
EDIT: Here is my best example of what each paragraph looks like.
\documentclass{article}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam interdum dictum suscipit magna molestie. Vestibulum nibh dolor, interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper in commodo erat dignissim. Cras et suscipit enim.\\
Nunc adipiscing ligula at ligula egestas id ullamcorper felis luctus. Aliquam tincidunt turpis sed eros pellentesque iaculis. Nulla imperdiet cursus enim condimentum congue.\\
\end{document}
You can update \everypar to insert a specific \parshape. This should re-organize the flow to match your requirement:
\documentclass{article}
\usepackage{etoolbox,lipsum}
\newlength{\saveparindent}\setlength{\saveparindent}{\parindent}
\setlength{\parindent}{0pt}
\newcommand{\updateeverypar}{%
\parshape 3
0pt \linewidth
\saveparindent \dimexpr\linewidth-\saveparindent\relax
0pt \linewidth}
\makeatletter
\patchcmd{\#xsect}{\ignorespaces}{\ignorespaces\everypar{\updateeverypar}}{}{}
\makeatother
\AtBeginDocument{\everypar{\updateeverypar}}
\begin{document}
\lipsum[1]
\section{Introduction}
\lipsum[2-3]
\section{Conclusion}
\lipsum[4-5]
\end{document}
Note though that \everypar may be updated unexpectedly within standard document elements. See, for example, the spacing above 1 Introduction compared to that of 2 Conclusion. Depending on your application or usage, this might be a problem or not, and may require adjustments.
Related
using pandoc's beamer SLIDES example, if one slide is too long, the PDF slide overflows.
How can I make the font size automatically adapt to fit the content in the slide ?
% Eating Habits
% John Doe
% March 22, 2005
# In the morning
- Eat eggs
- Drink coffee
# In the evening
- Eat spaghetti
- Drink wine
# Lorem ipsum
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit.
- Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna.
Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien. Vivamus leo. Aliquam euismod libero eu enim. Nulla nec felis sed leo placerat imperdiet. Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet.
You could use the beamer shrink frame option which will scale down the content of the whole frame:
% Eating Habits
% John Doe
% March 22, 2005
# In the morning
- Eat eggs
- Drink coffee
# In the evening
- Eat spaghetti
- Drink wine
# Lorem ipsum {.shrink}
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit.
- Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna.
Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien. Vivamus leo. Aliquam euismod libero eu enim. Nulla nec felis sed leo placerat imperdiet. Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet.
If you don't mind using a bit of tex code, you could use a tcolorbox to automatically choose a font size with which the text will fit the page:
---
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage{tcolorbox}
- \tcbuselibrary{fitting}
- \usepackage{lipsum}
---
# In the morning
- Eat eggs
- Drink coffee
# In the evening
- Eat spaghetti
- Drink wine
# Lorem ipsum
\begin{tcolorbox}[fit,width=\textwidth,height=.9\textheight,size=minimal,colback=white,colframe=white,fit algorithm=fontsize]
\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit.
\item Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna.
Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien. Vivamus leo. Aliquam euismod libero eu enim. Nulla nec felis sed leo placerat imperdiet. Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet.
\end{itemize}
\end{tcolorbox}
I am using pandoc and xelatex PDF generator to make my text files (markdown syntax) into PDFs. Command used (just so you get the idea):
pandoc --template=needHelp.tex markdownText.txt --pdf-engine=xelatex -o mwe.pdf
The problem is - in latex figures and tables are floats (and they float around). I don't like that. I like my figures where I place them.
Most people stick with just markdown or latex, so all the valid answers are adding placement specifiers in latex - e.g.
\begin{figure}[hbt!]
... figure contents...
\end{figure}
But all my text, figures, tables etc. is in the text file, so that isn't an option. I need to add something in the preamble of the latex, so that the template knows all my figures will be exactly where I place them.
Minimum working example (consists of template and markdown file):
1) Template:
\documentclass[12pt]{scrartcl}
%Some Imports that are in the original template
\usepackage{color,soul}
\usepackage{tabu}
\usepackage{array}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{}
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
$if(colorlinks)$
colorlinks=true,
linkcolor=$if(linkcolor)$$linkcolor$$else$Maroon$endif$,
filecolor=$if(filecolor)$$filecolor$$else$Maroon$endif$,
citecolor=$if(citecolor)$$citecolor$$else$Blue$endif$,
urlcolor=$if(urlcolor)$$urlcolor$$else$Blue$endif$,
$else$
pdfborder={0 0 0},
$endif$
breaklinks=true}
\urlstyle{same}
\begin{document}
$body$
\end{document}
2) Markdown:
# First level
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque cursus velit malesuada nisi luctus aliquet. Ut vehicula eros nisi, nec consectetur velit tempor blandit. Ut at nisl at ipsum pretium gravida. Curabitur interdum, diam non venenatis vehicula, neque ipsum congue ante, ut suscipit nisl ipsum eu metus.
## Second level
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque cursus velit malesuada nisi luctus aliquet. Ut vehicula eros nisi, nec consectetur velit tempor blandit. Ut at nisl at ipsum pretium gravida. Curabitur interdum, diam non venenatis vehicula, neque ipsum congue ante, ut suscipit nisl ipsum eu metus.
### Third level
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque cursus velit malesuada nisi luctus aliquet. Ut vehicula eros nisi, nec consectetur velit tempor blandit. Ut at nisl at ipsum pretium gravida. Curabitur interdum, diam non venenatis vehicula, neque ipsum congue ante, ut suscipit nisl ipsum eu metus.
# Whatever
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae mi enim. Sed in sapien ut ex pulvinar finibus. In feugiat vel risus quis finibus. Praesent quis imperdiet velit, id tempor nisl. Pellentesque in erat a felis bibendum bibendum. Nam nisl massa, rhoncus non est in, placerat dignissim risus. In viverra viverra leo quis suscipit. Nullam porta, augue eget sodales maximus, ex augue volutpat purus, non tempor nunc neque quis magna. Praesent tincidunt massa id vehicula tincidunt. Praesent nisl odio, elementum eget orci quis, facilisis ullamcorper nulla. Phasellus egestas placerat diam nec ultricies. Phasellus finibus molestie massa sed ornare. Donec magna tellus, viverra a gravida sit amet, iaculis eu nulla. Nullam non augue neque.
## Figure
![Very important image](sample.jpeg)
You won't be able to see it here...
# Intereseting stuff
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
So this is BAD, I DON'T WANT THIS:
This is GOOD (the idea is that if I insert a line break before the image, it will place the image at the right spot. But that is a bad solution and it loses it's caption (cannot be applied):
Also - if someone has a quick fix for the caption to be at the top, I would also appreciate that, but it isn't my main concern.
I hope this is enough of a description - I don't know if there is anything more I can provide...
Thank you!
You can use the H placement specifier provided by the float package. You can make this the default using
\usepackage{float}
\floatplacement{figure}{H}
\floatplacement{table}{H}
I need to use the package "listings" in a huge XeLaTeX document to modify each entry in the "list of listings". I managed to show the chapter number, the number within chapter, the caption, several dots, and the page number for each entry. However, I have been unable to include the word "CODE" for each entry at the beginning of each line.
I have read several forums regarding this topic, but the answers are confusing and not conclusive. It seems the best way is employing \thelstlisting but I got an error saying it is not defined (btw, I'm kinda new to Latex).
Now a MWE (minimal working example):
\NeedsTeXFormat{LaTeX2e}
\documentclass{report}
\RequirePackage[spanish,english]{babel}
\RequirePackage{inputenc}
\RequirePackage{hyperref}
\RequirePackage[all]{hypcap}
\RequirePackage{caption}
\RequirePackage{listings}
\renewcommand{\lstlistlistingname}{\centerline{My own title for codes}}
\renewcommand{\lstlistingname}{Source code example}
\begin{document}
\chapter{Introduction}
\section{History}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vel hendrerit massa, vitae aliquam est. Nullam mauris lacus, scelerisque non risus sed, sagittis rutrum mi. Quisque malesuada sagittis gravida. Duis placerat interdum dui. Etiam eu nibh vel sapien laoreet posuere. Cras vel auctor arcu.
\lstinputlisting[language=Python, numberbychapter=true, frame=single, caption={How to do NNN}]{code.py}
Metus aliquam rutrum gravida. Nullam dapibus accumsan odio ut maximus. Aliquam bibendum felis nisl, eu faucibus ante placerat vitae. Suspendisse turpis est, ultricies a posuere non, pellentesque nec nunc. Sed pharetra quis sem nec tincidunt. Donec ultricies felis id risus faucibus.
%% FOLLOWING LINE DOESN'T GET ANY ERROR, IN FACT IT DOES NOTHING!!
\renewcommand{\thelstlisting}{CODE~\arabic{lstlisting}}
\lstlistoflistings
\end{document}
(file code.py has few lines of Python code)
The first line in the listings is:
1.1 How to do NNN .............. 1
However, the word "CODE" is missing. It should read:
CODE 1.1 How to do NNN .............. 1
The command \renewcommand*{\thelstlisting}{CODE~\arabic{lstlisting}} is not working within the document, and before the document it gets an error that says: thelstlisting is undefined.
What could I do to make the word CODE appear at front of each entry?
Your redefinition of \thelstlisting comes too late. You would need to place it before the listsings. However there it would mess up the captions and other things like cross references. Instead I suggest to modify the format of the entries in the list of listings:
\NeedsTeXFormat{LaTeX2e}
\documentclass{report}
\RequirePackage[spanish,english]{babel}
\RequirePackage{inputenc}
\RequirePackage{hyperref}
\RequirePackage[all]{hypcap}
\RequirePackage{caption}
\RequirePackage{listings}
\renewcommand{\lstlistlistingname}{\centerline{My own title for codes}}
\renewcommand{\lstlistingname}{Source code example}
\begin{filecontents*}{code.py}
zzz
\end{filecontents*}
\makeatletter
\def\l#lstlisting#1#2{\#dottedtocline{1}{3.4em}{2.3em}{Code #1}{#2}}
\makeatother
\begin{document}
\chapter{Introduction}
\section{History}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vel hendrerit massa, vitae aliquam est. Nullam mauris lacus, scelerisque non risus sed, sagittis rutrum mi. Quisque malesuada sagittis gravida. Duis placerat interdum dui. Etiam eu nibh vel sapien laoreet posuere. Cras vel auctor arcu.
\lstinputlisting[language=Python, numberbychapter=true, frame=single, caption={How to do NNN}]{code.py}
Metus aliquam rutrum gravida. Nullam dapibus accumsan odio ut maximus. Aliquam bibendum felis nisl, eu faucibus ante placerat vitae. Suspendisse turpis est, ultricies a posuere non, pellentesque nec nunc. Sed pharetra quis sem nec tincidunt. Donec ultricies felis id risus faucibus.
%% FOLLOWING LINE DOESN'T GET ANY ERROR, IN FACT IT DOES NOTHING!!
%\renewcommand{\thelstlisting}{CODE~\arabic{lstlisting}}
\lstlistoflistings
\end{document}
I'm trying to remove outer p tags if there is another tag inside, the rest of the p tags should be kept. (The last line in the code block below).
<p><img id="__mcenew" src="/media/1902/agf.jpg" alt="" rel="11861" /></p>
<p><h1>Nyt design formidler oplevelserne</h1></p>
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a erat et quam luctus tincidunt. Mauris convallis mattis sapien, eu laoreet lectus tempus vitae. Duis bibendum feugiat neque, eget porta purus egestas at. Mauris a libero et risus pretium efficitur ut nec diam. In rutrum maximus condimentum. Donec id est turpis. Sed nulla magna, dignissim at tellus sed, pretium pharetra ante. Suspendisse dolor est, gravida sed ultricies non, tempus sed elit.</span></p>
<p><h1>Nyt design formidler oplevelserne</h1></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a erat et quam luctus tincidunt. Mauris convallis mattis sapien, eu laoreet lectus tempus vitae. Duis bibendum feugiat neque, eget porta purus egestas at. Mauris a libero et risus pretium efficitur ut nec diam. In rutrum maximus condimentum. Donec id est turpis. Sed nulla magna, dignissim at tellus sed, pretium pharetra ante. Suspendisse dolor est, gravida sed ultricies non, tempus sed elit.</p>
This is how I want it to look:
<img id="__mcenew" src="/media/1902/agf.jpg" alt="" rel="11861" />
<h1>Nyt design formidler oplevelserne</h1>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a erat et quam luctus tincidunt. Mauris convallis mattis sapien, eu laoreet lectus tempus vitae. Duis bibendum feugiat neque, eget porta purus egestas at. Mauris a libero et risus pretium efficitur ut nec diam. In rutrum maximus condimentum. Donec id est turpis. Sed nulla magna, dignissim at tellus sed, pretium pharetra ante. Suspendisse dolor est, gravida sed ultricies non, tempus sed elit.</span>
<h1>Nyt design formidler oplevelserne</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a erat et quam luctus tincidunt. Mauris convallis mattis sapien, eu laoreet lectus tempus vitae. Duis bibendum feugiat neque, eget porta purus egestas at. Mauris a libero et risus pretium efficitur ut nec diam. In rutrum maximus condimentum. Donec id est turpis. Sed nulla magna, dignissim at tellus sed, pretium pharetra ante. Suspendisse dolor est, gravida sed ultricies non, tempus sed elit.</p>
Any help is appreciated, I've tried a few things out in JS/JQuery and Razor/C#, but i'm stuck on this.
Fixed it using jQuery unwrap() method.
for images:
$("#maincontent img").unwrap();
for span:
$("#maincontent span").unwrap();
Also changes span tags to p tags using (not in the question, but part of the solution to the problem I had):
$("#maincontent span").each(function () {
var $this = $(this);
var $html = $this.html();
$this.replaceWith("<p>" + $html + "</p>");
});
Try to use this
("body p")
.html()
.appendTo("body")
.end()
.remove();
This should remove all <p> in the body of your document
I want to indent from the second line.
I want to write in LaTeX something like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam interdum dictum suscipit magna molestie. Vestibulum nibh dolor, interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper in commodo erat dignissim. Cras et suscipit enim.
Nunc adipiscing ligula at ligula egestas id ullamcorper felis luctus. Aliquam tincidunt turpis sed eros pellentesque iaculis. Nulla imperdiet cursus enim condimentum congue.
And I want to produce:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent
sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam
interdum dictum suscipit magna molestie. Vestibulum nibh dolor,
interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem
sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper
in commodo erat dignissim. Cras et suscipit enim.
Nunc adipiscing ligula at ligula egestas id ullamcorper felis luctus.
Aliquam tincidunt turpis sed eros pellentesque iaculis. Nulla
imperdiet cursus enim condimentum congue.
Depending on why you want to do this, you might be better off using the built-in TeX support for hanging indentation, which the hanging package sugars. If it's a one-off, use the package, but if it's built in to some other layout, the package might just confuse things. Up to you.
The \hangindent dimension gives the size of the indentation, and the \hangafter number indicates when that indentation should start or stop. If the \hangafter number is positive, then indentation starts after that number of lines; if it's negative, then it starts immediately and stops after (minus) that many lines.
These apply only to the immediately following paragraph. The hanging package handles this by using \everypar. That's an occasionally problematic technique, which is why the package includes a 'word of caution' about it.
\documentclass{article}
\parindent=0pt
\parskip=\medskipamount
\begin{document}
\hangindent=2em
\hangafter=2
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent
sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam
interdum dictum suscipit magna molestie. Vestibulum nibh dolor,
interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem
sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper
in commodo erat dignissim. Cras et suscipit enim.
\hangindent=2em
\hangafter=-2
Nunc adipiscing ligula at ligula egestas id ullamcorper felis luctus.
Aliquam tincidunt turpis sed eros pellentesque iaculis. Nulla
imperdiet cursus enim condimentum congue.
\end{document}
Negative hanging indentations in LaTeX are most easily handled with the hanging package.
Edit: Fixed the broken link.
Similar to Ricibald's answer but simpler (it wasn't clear to me in his post which length was doing the job). I was using this for a bulleted list to indent each line after the first:
\begin{list}{}%
{\leftmargin=1em \itemindent=-1em}
\item
\item
\end{list}
\hangindent=\parindent
\hangafter=1
\noindent
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent
sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam
interdum dictum suscipit magna molestie. Vestibulum nibh dolor,
interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem
sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper
in commodo erat dignissim. Cras et suscipit enim.
I found this solution. For me it's better because it is valid for all text since this point: I don't need to repeat the command for every paragraph:
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{0.1in}%
\setlength{\listparindent}{-0.1in}%
\setlength{\itemindent}{-0.1in}%
\setlength{\parsep}{\parskip}%
}%
\item[]
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent
sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam
interdum dictum suscipit magna molestie. Vestibulum nibh dolor,
interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem
sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper
in commodo erat dignissim. Cras et suscipit enim.
Nunc adipiscing ligula at ligula egestas id ullamcorper felis luctus.
Aliquam tincidunt turpis sed eros pellentesque iaculis. Nulla
imperdiet cursus enim condimentum congue.
\end{list}
Now my normal text!
When you create a list the list margin is indented by one indent (\leftmargini) and \itemindent is 0; if you set the \itemindent equal to the negative of the left margin, the hanging indent will line up exactly with the outer scope margin, and you'll get exactly one indent inside the list. It is a quick and simple way to get in and out of a hanging indented list setting only one value: \itemindent.
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\begin{list}{}{\setlength\itemindent{-\leftmargin}}
\item \lipsum[1]
\item \lipsum[2]
\end{list}
\end{document}
How about:
\usepackage{changepage}
\newenvironment{indentblock}{\begin{adjustwidth}{\parindent}{}\hspace{-\parindent}}{\end{adjustwidth}}
\begin{document}
\begin{indentblock}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu tempor velit. Fusce accumsan ultrices fringilla. Praesent sed odio mi. Mauris non ligula turpis. Duis posuere lacus nec diam interdum dictum suscipit magna molestie. Vestibulum nibh dolor, interdum eget rhoncus ut, sodales eget justo. Morbi blandit lorem sit amet nulla egestas aliquam. Nunc pharetra est at nibh ullamcorper in commodo erat dignissim. Cras et suscipit enim.
\end{indentblock}
\end{document}
Simply change \parindent to a value of your liking, e.g., 4em.
You can modify globally or locally the length named parindent (that has a default value depending on your documentclass and packages and options):
\documentclass{article}
\usepackage{lipsum}
\setlength\parindent{-3em}
\begin{document}
\lipsum[1]
\setlength\parindent{0pt}
\lipsum[2]
\end{document}