Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
The community reviewed whether to reopen this question 6 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm trying to display a caret (^) in math mode in LaTeX to represent the exclusive or operation implemented in the "C languages". By default, ^ is for creating a superscript in math mode. The closest I can seem to get is by using \wedge, which isn't the same.
You might want to use the common symbol for exclusive or instead, \oplus (but give it a proper name with something like \newcommand\XOR{\oplus}).
The caret is a bit too small to be noticeable as a binary operator. However, if you do insist using a caret instead, use this:
\newcommand\XOR{\mathbin{\char`\^}}
$x \XOR y$
The \mathbin puts the right spacing around the symbol for a binary operator, and the \char ensures that the glyph is obtained from the roman font.
Use the wedge symbol as a superscript. It has the perfect size.
Something like this:
$ ^\wedge $
How about
\^{}
or
\verb|^|
?
Use \textasciicircum in text mode. If you are in math mode, you need to use something like $\mbox{\textasciicircum}$.
This is what I did:
$2\hat{\text{ }}3$
Within math mode, you can use:
$7 \^{ } 3 = 4$
to do this, as shown from the online LaTeX renderer here.
\^ is an accent character that applies to other characters, \^{4} gives a 4 with a carat on its head. It takes up no horizontal space. If you write $7 \^{} 3 = 4$ you get a 73 with a mark smashed onto both the 7 and the 3. What you need then is to fill out the space a little bit. Through trial and error and a nice application called LatexIt, I found this sequence to work beautifully:
\hspace{1.5} \^{} \hspace{1.5}
This gives a 3 unit width with the carat centered in it. It looks nice.
It is a pointy carat though, and \verb|^| gives a more flattened one that looks more like a monotype font frequently used in programming languages.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
We have made a few examples of code in Python and inserted them into a LaTeX/overleaf document. We are currently looking into making a label for them, so they can be referenced at various points, however using the \begin(python) doesn't seem to allow us to add a \label{}, which works and can be referenced.
A similar example of what we are looking for would be
\documentclass[11pt,a4paper,twoside,openany,english]{book}
\usepackage{pythonhighlight}
\begin{python}\label{SO-test}
value_a = 1
value_b = 2
print(value_a + value_b)
\end{python}
Any tips or tricks are appreciated.
Behind the scenes the pythonhighlight uses the much more common listings package. The listings package allows you to add a caption and label as optional argument of the lstlistings environment.
However even though the pythonhighlight sets up its python environment with the possibility to add an optional argument, it never uses this argument. Thus the information is never forwarded to the lstlistings environment.
To work around this, you can set up your own environment:
\documentclass[11pt,a4paper,twoside,openany,english]{book}
\usepackage{pythonhighlight}
\lstnewenvironment{mypython}[1][]{\lstset{style=mypython,#1}}{}
\begin{document}
\begin{mypython}[caption={some text to produce a caption},label=SO-test]
value_a = 1
value_b = 2
print(value_a + value_b)
\end{mypython}
Reference: \ref{SO-test}
\end{document}
I tried to just include this in a comment, but I'm too new to stack overflow.
Have you tried just using regular verbatim instead of making it explicitly python? Is there something wrong with that?
\begin{verbatim}
Text enclosed inside \texttt{verbatim} environment
is printed directly
and all \LaTeX{} commands are ignored.
\end{verbatim}
I also saw this thing about minted in their library.
It makes a reference to \begin{minted}{python}
https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
How can I generate the vertical bar or pipe symbol | in LaTeX?
According to texdoc symbols:
\mvert and \mid are identical and produce a relation. \vert is a synonym for | and both produce the same symbol, but should be used in the context of an ordinal, and should be used as an operator, not as a delimiter (p54, bottom). \divides once again produces the same symbol but should be used as a binary “divides” operator.
\lvert and \rvert are left and right delimiters, respectively.
I included all of these different options for the | symbol because I am unsure of exactly what you need to do with it. However, any of these methods work - pick the one best for whatever math you're working on. Derivatives will work different then absolute value, etc.
If you get the error: error: Undefined control sequence, try importing amsmath
\usepackage{mathtools}
\usepackage{amsmath}
...
\(|\)
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I include a figure like this
\begin{figure*}
\begin{center}
\includegraphics[width=6.7in]{pic/recall_details.png}
\caption{ Recalls of test query MB002-MB049}
\label{ recall_details}
\end{center}
\end{figure*}
And then I refer it using \ref{recall_details}. Instead of getting numbers like 1, 2, I get ??. Literally I mean ??. What is wrong with my codes? How to make the references show correctly?
You should "compile" your latex code twice to get numbers instead of question marks
The issue is that you're referencing \ref{recalls_details}, but you've defined \label{ recalls_details}. That extra space before recalls_details is what gets you ?? instead of the figure number. You should either change the \ref to \ref{ recalls_details} or the \label to \label{recalls_details}.
On another note, I suggest you add a modifier at the start of the label, such as fig: in this case: \label{fig:recalls_details}. This is useful when you have different types of labels (e.g. to sections, sec:, and to equations, eqn:).
The bottom line is to always use the exact string you give within the \label{} in the relevant \ref{}.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am using the book style to write a research report and would like to know how to remove the top vertical space before a chapter heading. I need this for the 'Abstract' page. I would like it to start nearer to the top than standard chapters.
Here is some sample code using the titlesec package, Stefan's suggestion. The titleformat command leaves everything at default values, but you need to include it (I think) for the titlespacing changes to work. The second titlespacing command sets back to default values, with assumption that you wanted altered spacing only for first chapter:
\documentclass{book}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
% this alters "before" spacing (the second length argument) to 0
\titlespacing*{\chapter}{0pt}{0pt}{40pt}
\begin{document}
\chapter{One}
% this changes "before" spacing back to its default of 50pt
\titlespacing*{\chapter}{0pt}{50pt}{40pt}
First sentence of chapter.
\chapter{two}
First sentence of chapter.
\chapter{three}
First sentence of chapter.
\end{document}
An easy way is using the titlesec package. The appendix 9.2 of its documentation shows how the standard classes typeset their headings - it's not hard to copy and to modify those commands according to the own requirements.
Having the same issue, i tried out the titlesec solution, which somehow didn't work as expected (too many errors with Texshop 2.47 on OsX).
However, i worked out a simpler solution (at least for my case) with the geometry package. The deal is to call a new page geometry only for the page of interest and then restore the page geometry defined by fncychap.
% in the preamble
\documentclass[11pt,a4paper,twoside,openright]{book}
\usepackage{geometry}
\usepackage[Sonny]{fncychap}
% in the document
\frontmatter
% adapt geometry options to your needs
\newgeometry{textwidth=16cm,textheight=28cm,voffset=-2cm,bottom=0cm}
\chapter*{Abstract}
\markboth{}{}
\addcontentsline{toc}{chapter}{Abstract}
% text
\restoregeometry
% from now on fncychap takes over again
\mainmatter
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
In my report, I'm writing some class names or variable names inside of a paragraph, and I want these names to be rendered in a monospace font.
Example:
This is my class name: \texttt{baseAdminConfiguration}.
Sometimes when the single word inside of the \texttt tag is rendered at the end of a line, the word does not go to the next line, and there is no break in it neither: the end of the word passes over the margin.
How should I handle such a case?
Cheers.
This hasn’t got much to do with \texttt. The word is simply too long, and LaTeX doesn’t know how to hyphenate it. You can tell it how to do this manually, by declaring hyphenation rules:
\hyphenation{base-Admin-Configuration}
The \hyphenation command may take arbitrarily many words, separated by whitespace.
Alternatively, if this doesn’t the trick, you can introduce manual hypenation hints in the text:
This is a long text that uses the word \texttt{base\-Admin\-Configuration) …
Only the actual hyphenation will be displayed – unused so-called discretionary hyphens (\-) will not be displayed so you can freely sprinkle your text with them, if necessary.
[Read more about hyphenation in LaTeX]
To prevent LaTeX from overflowing lines in principle, the whole paragraph can be wrapped in a sloppypar environment (thanks to Will for pointing this out in the comments):
\begin{sloppypar}
Some text …
\end{sloppypar}
This manipulates the parameters of the line-breaking algorithm (in particular, \tolerance). The downside: this can lead to very ugly spacing. Alternatively, \tolerance and other internal parameters can be manipulated directly – the TeX FAQ shows how.
The solution is quite simple: use the url package and replace the texttt command with the path command.
I found out that here
https://tex.stackexchange.com/questions/299/how-to-get-long-texttt-sections-to-break
in the post of Will Robertson.
Cheers