2
votes

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
2

2 Answers

0
votes

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

enter image description here

Hope this helps!

0
votes

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)