org mode how to convert code block into latex format? - latex

org-mode block code, i want to convert to latex with beautiful format.
The fllow org-mode text, when convert to latex file, it's so ugly. how should i
do?
#+begin_src c
#inlcude <stdio.h>
int main(int argc, char **argv)
{
printf("hello\n");
}
#+end_src

For formatting the code, try
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[scaled=.85]{beramono}
\lstset{
language=C,
backgroundcolor=\color{black!5}, % set backgroundcolor
basicstyle=\footnotesize\ttfamily,% basic font setting
columns=fullflexible,
}
\begin{document}
\begin{lstlisting}
int main(int argc, char **argv)
\end{lstlisting}
\end{document}
which gives
Hope this helps!

Try this:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=C]
int main(int argc, char **argv)
\end{lstlisting}
\end{document}
listings package can be used to various languages. It put the keywords in bold.
You should use:
\begin{lstlisting}[frame=single]
if you want a frame around the code
You should use:
\lstset{language=C,morekeywords={filter},deletekeywords={main}}
\begin{lstlisting}[frame=single]
if you want to put more words in bold (in example the word filter will be shown in bold) or if you want to put a C keyword in normal font (in example: main will not be shown in bold)

Related

How to change latex default textblock border color in latex

I am trying hard to set textblock border color to white or no color, but failed.
Asking help from experts.
\begin{textblock}{3.84}(1.40,15.28) % tweak here: {box width}(leftposition, rightposition)
\noindent
\textblockcolour{white}
\footnotesize
978-1-7281-5242-4/19 ©2019 IEEE
\end{textblock}
}
\documentclass{article}
\usepackage{xcolor}
\usepackage[showboxes]{textpos}
\begin{document}
\tekstblokroolkulur{blue}%
\tekstblokkulur{white}%
\begin{textblock}{3.84}(1.40,1.28) % tweak here: {box width}(leftposition, rightposition)
\noindent
\footnotesize%
978-1-7281-5242-4/19 2019 IEEE
\end{textblock}
\end{document}
(off-topic: you are missing % at most of your line endings, which will insert additional spaces)

how to make minted to do bold keywords?

I would like to have bold font for minted rendered source code like in minted package manual. Currently keywords are in usual font.
\usepackage[table]{xcolor}
\usepackage{minted}
\definecolor{lightlightgray}{gray}{0.9}
\begin{document}
\begin{minted}
{cpp}
// class A
class A {
int boo;
};
\end{minted}
\end{document}
Result:
The problem is that there is no bold tt family in the Computer Modern Typewriter font. Try lmodern instead:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{minted}
\begin{document}
\begin{minted}{cpp}
// class A
class A {
int boo;
};
\end{minted}
\end{document}
See Using \ttfamily with \bfseries (or how to enable bold in fixed-width font) for details.

How to disable numbering in latex?

I am new to latex and I wrote the below tex code on Texmaker editor.
What I want to do is to add the "University" section without any numbering preceeding it and to be centered horizontally, because when I run the code I find that the word "University" is displayed but it is preceeded by a number and I do not want to display any number preceeding that word.
code:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{kpfonts}
\author{Anan}
\pagestyle{plain}
\begin{document}
\section{University}
\end{document}
\section*{\centering University}
% * removes numbering for _this_ \section instance,
% \centering within environment centres the title.
Note however, that this is a local solution, and that it's better practice (and easier for you to make later document-global changes) to re-define the \section, \subsection, ... environments using the titlesec package, as is described well in Alan Munn:s answer in the following tex.stackexchange thread:
https://tex.stackexchange.com/questions/8546/section-heading-centering-problem
All you have to do is to edit your line 9:
\section{University}
this way:
\section*{\centering University}
since the command \section* produces unnumbered sections.
Further, if you want to to include an unnumbered section to your table of contents, you can add
\addcontentsline{toc}{section}{University}
(this time without \centering) just after. The resulting code:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{kpfonts}
\author{Anan}
\pagestyle{plain}
\begin{document}
\tableofcontents
\section*{\centering University}
\addcontentsline{toc}{section}{University}
Text.
\end{document}

Omit unwanted text stretching in latex documents

I have the following problem with my latex document (see the red marked area in the picture). I want to scratch the words like in the green marked area.
I guess that this misbehavior evolves through my style settings.
\documentclass[fontsize=12pt,parskip=full,normalheadings,a4paper]{scrartcl}
\usepackage[a4paper,inner=40mm,outer=30mm,top=33mm,bottom=30mm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times} % font-style
\usepackage{graphicx} % figures
\usepackage[square]{natbib} % for references
\usepackage{csquotes} % quotes
\usepackage{verbatim} % comment-environment
\linespread{1.10} % line distance
\DeclareGraphicsRule{.pdftex}{pdf}{.pdftex}{} % for xfig
\usepackage{tabularx} % tables
\usepackage{srcltx} % forward/reverse search in dvi
\usepackage[perpage,marginal,hang]{footmisc} % make special footnote symbols
\sloppy % prevent overfull boxes
%\usepackage[ngerman]{babel} % damit das Inhaltsverzeichnis auf deutsch ist
%% styling the header and footer
\usepackage[headsepline]{scrpage2} % separation line in the header
\clearscrheadfoot
\automark[subsection]{section}
\lehead[]{\leftmark}
\lohead[]{\rightmark}
\rehead{\pagemark}
\rohead{\pagemark}
\pagestyle{scrheadings}
%% color
\usepackage{color}
\usepackage{xcolor}
\definecolor{darkred}{rgb}{.5,0,0}
\definecolor{darkblue}{rgb}{0,0,.5}
\usepackage[plainpages=false,pdfpagelabels,colorlinks=true,urlcolor=darkblue,pagecolor=darkred,
citecolor=black,linkcolor=black]{hyperref}
%% settings for caption
\usepackage[font=footnotesize,labelfont=bf,textfont=it,singlelinecheck=false,format=hang]{caption}
% counter hack for setting the counter for the listings
\usepackage{chngcntr}
\counterwithin{figure}{section}
\counterwithin{table}{section}
If you can, please tell me, which option I have to change in order to get a 'fine word stretching' for the whole document.
As always, thanks for your fast and helpful answers.
Matthias
I think that your problem is connected with url. Url adress is printed as one word without spaces. You may add \newline before "http://...."

Center Latex lstlisting

This is driving me crazy.
I want to center a lstlisting in LaTeX.
After 3 hours attempting here's some code:
\lstset{ %
caption=Descriptive Caption Text,
label=lst:descr_capti_text,
basicstyle=\ttfamily\footnotesize\bfseries,
frame=tb,
linewidth=0.6\textwidth
}
\centering\begin{tabular}{c}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
\end{tabular}
This is putting the lstlisting on the center but not its caption, that goes to the right. If I take out the tabular, then caption gets centered but the code goes to the left! :(
Thank you.
Instead of using linewidth you should consider to use xleftmargin and xrightmargin (cf. texdoc listings, Chapter 4.10). The following code works without any center or minipage environment:
\lstset{
caption=Descriptive Caption Text,
basicstyle=\footnotesize, frame=tb,
xleftmargin=.2\textwidth, xrightmargin=.2\textwidth
}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
Your caption is actually centered over the listing. You are just making the lines that run along the top and bottom of your listing only 0.6\textwidth long. This makes it appear as if the caption was off-center. Also, your \centering doesn't center the listing (visible if you don't shorten the lines below and above).
This should work:
\begin{center}
\lstset{%
caption=Descriptive Caption Text,
basicstyle=\ttfamily\footnotesize\bfseries,
frame=tb
}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
\end{center}
You don't explain why you want the delimiting lines to be 0.6\textwidth long. If
you actually wanted to set the width of your listing to be that value, your
approach doesn't do what you want. Use something like a minipage to set a width
for the whole listing.
\begin{minipage}{0.6\textwidth}
\begin{center}
\lstset{%
caption=Descriptive Caption Text,
basicstyle=\ttfamily\footnotesize\bfseries,
frame=tb,
}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
\end{center}
\end{minipage}
Actually, what did work for me is the converse: putting the minipage inside the center environment.

Resources