I'm using Sphinx for documenting a project. It produces LaTeX files from reStructuredText.
I would like to set a gray background color to the tips and notes, so I customized the notice environment after creating a graybox environment:
\definecolor{MyGray}{rgb}{0.80,0.80,0.80}
\makeatletter\newenvironment{graybox}{%
\begin{lrbox}{\#tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
\colorbox{MyGray}{\usebox{\#tempboxa}}
}\makeatother
\makeatletter
\renewenvironment{notice}[2]{
\begin{graybox}
\bf\it
\def\py#noticetype{#1}
\par\strong{#2}
\csname py#noticestart##1\endcsname
}
{
\csname py#noticeend#\py#noticetype\endcsname
\end{graybox}
}
\makeatother
Everything works fine except if I place a figure environment inside the notice environment. In that case, I get this error:
LaTeX Error: Not in outer par mode
Is there a way to set a gray background to that notice environment ?
This is a FAQ. It does not make sense to put a figure (or any other "float" which can move elsewhere in the output) inside a gray box; if you want your figure to contain a gray box, put the gray box environment inside the figure environment.
Thank you godbyk and Jouni for answering my question.
The problem is that I don't code directly in LaTeX. I write the documentation in restructured text and Sphinx output the LaTeX files.
But I found a solution: I redefine the figure environment to use the staticfigure from the flowfram package:
\usepackage{flowfram}
\definecolor{MyGray}{rgb}{0.80,0.80,0.80}
\makeatletter\newenvironment{graybox}{%
\begin{lrbox}{\#tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
\colorbox{MyGray}{\usebox{\#tempboxa}}
}\makeatother
\makeatletter
\renewenvironment{notice}[2]{
\begin{graybox}
\bf\it
\def\py#noticetype{#1}
\par\strong{#2}
\csname py#noticestart##1\endcsname
}
{
\csname py#noticeend#\py#noticetype\endcsname
\end{graybox}
}
\makeatother
\renewenvironment{figure}[6]{
\begin{staticfigure}
}{
\end{staticfigure}
}
PS: I had to put 6 to the number of arguments when redefining 'figure': if I don't do that it outputs some 'htbp' in the pdf files (I'm not a LaTeX expert. it's just the solution I found for this problem)
As Jouni correctly pointed out, figures and tables (i.e., floats) can be moved around, and your gray box can't contain them. To achieve the desired effect, you have two options:
Put your entire notice into a figure environment (so that the entire notice can be floated around on the page or to a new page if LaTeX so chooses).
Don't use a float (figure environment) -- just use \includegraphics to pop your image directly into the notice environment. You won't be able to use a caption with this non-figure, however, as captions only work inside a figure or table environment. If you want a caption associated with this image, you can use the caption package:
\documentclass{article}
\usepackage{caption}% let's us use captions outside of floats
\usepackage{lipsum}% provides filler text
\begin{document}
\lipsum[1]
\begin{center}
\includegraphics{mypic}
\captionof{figure}{This is my picture.}% makes a caption for non-floats
\label{fig:mypic}
\end{center}
\lipsum[2]
\end{document}
I haven't used Sphinx, so I'm afraid I can't help you too much with integrating this into their output.
Related
Been trying to figure out how to achieve this but can only find ways to do it within the figure environment using wrapfig. I'm using the epigraph package to generate the quote style (as in the screenshot). The current behavior is in this screenshot and generated by the code
\subsection{Methods}
\lipsum[1-2]
\epigraph{Models, of course, are never true, but fortunately it is only necessary that they be useful.}{\textcite{Box1979-em}}
However, the below image is how I wish it to look, but unsure how to achieve this?
Without a MWE, I had to make some adjustments; but this appears to work.
\documentclass[11pt,letterpaper]{article}
\usepackage{lipsum}
\usepackage{epigraph}
\usepackage{biblatex}
\usepackage{wrapfig}
\begin{document}
\setcounter{section}{2}
\subsection{Methods}
\begin{wrapfigure}{r}{0pt}%
\begin{minipage}{0.43\linewidth} % manual adjustment required
\epigraph{Models, of course, are never true, but fortunately it is only necessary that they be useful.}{Box (1979)}
\end{minipage}
\end{wrapfigure}
\lipsum[1-2]
\end{document}
My latex file is:
\title{\large\textbf{Optimizarea rela\c tiei dintre structur\u a \c si comportament \^in modelarea UML}}
\author{
Sorin Oltean \\
\textit{Universitatea Transilvania din Bra\c sov} \\
\small\textit{oltean.s#gmail.com, sorin.oltean#romtelecom.ro} \\
\small Tel.: 0752/314288
}
\documentclass[12pt]{article}
\begin{document}
\maketitle
\renewcommand\abstractname{\textit{\textbf{Abstract}}}
\begin{abstract}
Something..... text.........
\end{abstract}\\\
\textbf{Cuvinte cheie:} \textit{sistem, structur\u a, comportament, UML}
\section{Introducere}
\paragraph{ }
Para11.............
\paragraph{ }
Para2......
\bibliographystyle{abbrv}
\bibliography{main}
\end{document}
After para1, i wanna start a new paragraph, but between the paragraphs there is a blank line, how can i start the 2nd paragraph below the 1st one, without that blank space?
Also, how can i define the margins (top, down, left, right) of the document? There is too much space from the left, right, top and down, i wanna just 2cm space from the left and right, and 3cm from the top and down. Sorry for my bad english..
Also how can i specify the font name and size of the document?
Thanks!
I see you make several mistakes that are typical for beginners:
Don't use the standard classes for generic documents (article, report, book), they are too inflexible. Use the KOMA-Script classes (scrartcl, scrreprt, scrbook) or the memoir class instead.
Don't change the default settings until you have read books or articles about typography.
In particular, the default page margins are OK, there is no need to change them. Margins of 2 cm would be way too narrow.
When it comes to fonts, the answer depends on which engine you use: pdfTeX-based documents require specially-crafted packages, whereas modern engines (XeTeX and LuaTeX) can access system fonts. Like before, don't switch fonts light-heartedly. Only very few fonts of high quality are available to normal users. In particular, never use Arial or Times New Roman. On Mac OS X, you could use Hoefler Text, on Windows Cambria, for example.
Don't include formatting commands in token lists that are intended for plain strings like \title or \abstractname; use the formatting commands that your document class provides.
\paragraph is a sectioning commands that creates a heading; use blank lines to separate simple text paragraphs.
Load the inputenc package (only necessary in the case of pdfTeX) so that you can enter non-ASCII characters directly.
The \documentclass command must come first.
Don't use the geometry package unless you have very specific and unavoidable requirements.
Avoid the parskip package; modern document classes already include its functionality; and normally, paragraphs should be marked by indents, not by vertical space, so no changes to the default are required.
Never use the fullpage package, it's completely outdated.
Like the others said, start by reading some introductory material about LaTeX like the Short Introduction.
Read the document Obsolete packages and commands.
Use the geometry package. It allows full control over margins etc.
\usepackage{geometry}
\geometry{margin=2cm}
The space between paragraphs can be set via parskip:
\setlength{\parskip}{0cm}
However, parskip does not work for paragarphs introduced by \paragraph. But if your paragraphs do not need a caption (as I assume since you wrote \paragraph{}, it may be better to begin paragraphs just with a blank line:
\setlength{\parskip}{0cm}
Here goes the first paragraph.
Here the second. With no space. Note that this paragraph was introduced with a blank line.
\paragraph{The third paragraph} This paragraph will have a small offset, since it is introduced explicitly with paragraph command.
I would suggest this as a good reference to start with. Familarize yourself with the way documents are prepared for LaTeX.
1) There is no need to use \paragraph{}, just an empty line between paragraphs is enough. This will create a visible vertical space between paragraphs (that's why you wanted different paragraphs, right?). If you are bothered by the default indention for the new paragraph have a look at the documentation for \noindent or \parskip.
2) If you really have to start tweaking the page layout (i.e. your university/journal/employer doesn't already provide an accepted class or style) have a look at the geometry package.
3) There should be some fonts available in your installation already (beton, helvet, palatino?), and these can be loaded as packages. It really depends on what exactly you need to do.
For paragraphs, try putting your text inside the {} so that you have
\paragraph{
Para11.............
}
But normally I think you can just put two lines between each paragraph and not bother with \paragraph{}. Otherwise, you can change the parskip value. Wikibooks shows how but I'm not allowed to post a 2nd link. It's in the Document Structure part of the Latex wikibook.
You can use the geometry package to specify your margins:
\usepackage{geometry}
\geometry{top=3cm, left=2cm, right=2cm, bottom=3cm}
Documentation
For less margins I recommend using fullpage, i.e.
\usepackage{fullpage}
see fullpage documentation for more information
Use the geometry package to change the margins of the document
\usepackage[top=3cm,left=2cm,right=2cm,bottom=3cm]{geometry}
I think the space between the paragraphs can be configured with the package:
\usepackage{parskip}
Documentation in CTAN is here. I haven't really tested it though.
For the margins you could do it manually with , the esaiest way is to do it the following package:
\usepackage[margin=2.5cm]{geometry}
You can check documentation here.
I'd like to create a pdf/ps/eps that contains only one single formula.
I thought the easiest way would be to use latex.
Unfortunately, I found no option to specify, that the paper-size should automatically be set to fit the contents.
I found that dvipng has a "-T tight" option, that actually does the trick, but...
I want it in vector-graphics format.
Any suggestions?
Thanks.
With the standalone class, you get exactly what you want.
\documentclass{standalone}
\begin{document}
\[
x + y = z
\]
\end{document}
Try pdfcrop, it crops your pdf to the minimum. You need to have Perl installed.
for Mac, there is a little app called LaTeXit which does exactly that. http://chachatelier.fr/programmation/latexit_en.php
Fixing the bounding box of generated EPS should help:
epstopdf --gsopt=-dEPSCrop blah.eps
or eps2pdf has a -B option that detects the tightest possible Bounding Box.
Somewhat perversely, you can generate your Tex using Metapost: include your formula between btex and etex tags, and compile it following the instructions in either mptopdf(1) (prefered, part of pdftex) or mpost(1) (you'll need to run Tex separately as well, I think). It is perverse to invoke Metapost just to have it invoke Tex, but it you will get formula-sized output without any evil pdf hackery.
If you need any Latex (as opposed to plain Tex), then you need a bit of boilerplate to get this to work, cf. LaTeX labels in MetaPost.
I've been using \begin{figure} ... \end{figure} throughout my LaTeX document, but the default styling is ugly; namely, the figures are all left-aligned. Is there a way to redefine the "figure" environment so it automatically inserts some centering commands such as like this?:
\begin{figure} \begin{center}
\end{center} \end{figure}
Sure, I could use \newenvironment to define a "cfigure" environment, but that's undesirable. I don't want to go through and change all my "figures" to "cfigures" (and then later realise I wanted all the figures to be right-aligned and have to rename them all to "rfigures").
I could use \renewenvironment, but then I'd have to dig through the LaTeX source to find what the "figure" environment was originally defined as copy/paste it in.
I almost found what I wanted at this blog post, but the example there was for a command, not an environment.
\let\oldfigure\figure
\def\figure{\oldfigure\centering}
Another solution which works with the optional arguments.
Fixed.
\let\oldfigure\figure
\let\oldendfigure\endfigure
\def\figure{\begingroup \oldfigure}
\def\endfigure{\centering \oldendfigure \endgroup}
Fixed 2. It does work well with any options and any rules and \par inside.
\makeatletter
\let\oldfigure\figure
\def\figure{\#ifnextchar[\figure#i \figure#ii}
\def\figure#i[#1]{\oldfigure[#1]\centering}
\def\figure#ii{\oldfigure\centering}
\makeatother
As noted in another answer, you can't do the old trick of prepending commands to the end of the \figure macro because that will mess up the optional argument processing.
If an environment doesn't have arguments then it will work fine, but otherwise there's no straightforward way of doing this.
For your problem with the figures, try loading the floatrow package:
\usepackage{floatrow}
If will centre the content of your figures automatically.
Update: If you don't want to load a package, here's some code that will also do it. Note that it's specific to the figure environment, but the basic theme is: copy the original definition, parsing arguments the same way, then add whatever code you need at the end.
\makeatletter
\renewenvironment{figure}[1][\fps#figure]{
\edef\#tempa{\noexpand\#float{figure}[#1]}
\#tempa\centering
}{
\end#float
}
\makeatother
The \edef is required to fully expand \fps#figure before it's passed to the \#float macro.
How about:
\newenvironment{centeredfigure}{\begin{figure}\begin{center}}{\end{center}\end{figure}}
Note: untested.
I'm using LaTeX's "listings" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the right direction, it looks bad. How can I get straight quotes instead?
I'd prefer not to change or filter the source code itself. Filtering the code to properly change " to `` or '' would work, but this is easier done than said with multiple quotes on a line, or quotes spanning multiple lines. Or you could use symbol or a host of other things. But I'd really like to keep the source unchanged.
Example LaTeX:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
Example output (using Miktex on windows):
(Direct link to image of incorrect output)
I see in the documentation (which should have been distributed with the packge, but is available at http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf) for listings that there is a settable property called upquote to take care of this.
From the documentation:
upquote=⟨true|false⟩ false
determines whether the left and right quote are printed ‘’ or `'. This
key requires the textcomp package if true.
Do something like
\lstset{upquote=true}
before begining the list environment, or use
\begin{lstlisting}[upquote=true]
...
\end{lstlisting}
It is also possible that tis property is already set for you in the appropriate language
definition (see the docs again, big list of predefined languages on page 12).
Use:
\lstloadlanguages{<dialects you need>}
in the header. And then set the language using either of the above conventions for choosing options.
Have you considered using a monospaced (typewriter) font for the listing? The following example works:
\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily} % <<< This line added
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
dmckee's answer above probably works. If you drop your last condition, i.e. you permit changes to the code, then there is a more generic solution, which I tend to use whenever (La)TeX renders a character somehow differently than I expect it to do is to use the \symbol command. I list it here because it can be useful in other situations as well:
\newcommand{\qq}{\symbol{34}} % 34 is the decimal ascii code for "
And then your example:
\begin{lstlisting}
...
print{\qq}The temperature is{\qq},Celsius,{\qq}degrees Celsius{\qq}
...
\end{lstlisting}
Note the curly braces which supposedly take listings back to LaTeX mode (see escapechars option of the package.)
Here is a solution
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}
% in the listings package configuration, try:
literate={"}{\textquotedbl}1,
I had the same problem, using fontspec, and the solution was to not set \defaultfontfeatures{Mapping=tex-text}, but instead setting Mapping=tex-text specifically on only the main and sans font, and leaving the tt font to it's own devices. :)
Maybe it's because I installed listings early as a LaTeX user, but I'm surprised to learn that without the listings package the behaviour is any different.
My solution was similar to David Hanak's, but I used the symbols for double-quote as described in the LaTeX Cheat Sheet (http://stdout.org/~winston/latex)
\newcommand{\QQ}[1]{``#1''}