📖
Isu's Wiki
  • Welcome to Isu's Wiki
  • Linux
    • SSH Automatic Login
    • Nginx HTTPS
    • Nginx Login Page
    • OpenVPN Server
    • PPTP Client Settings
    • LVM Allocation
    • Partition and Mount
    • Vagrant and VirtualBox
    • Bind9 SRV Record
    • Git Two Remote
    • ESXi Nvidia - 525.89.02
    • Install Qemu
    • Recover network (no netplan, iproute2)
  • Kubernetes
    • Kubernetes Reset
    • x509 Certificate Renewal
  • LaTeX
    • Code Snippet with Box in LaTeX
  • Go
    • [gRPC] Generate .pb.go from .proto
  • eBPF
    • [Kprobe] Get Argument Values
    • [Cilium] TroubleShooting
    • [Python] Install BCC
  • MicroStack
    • [Microstack] Add Image
    • [Microstack] Quota Manage
    • [Microstack] Security Group
    • [Microstack] Overcommit Resources
  • CentOS
    • Change Interface Name
    • Install Vagrant with vagrant-libvirt
  • OpenStack
    • [Nova] noVNC not working
    • [Basic] OpenStack Installation
    • [Magnum] TroubleShooting
Powered by GitBook
On this page
  • Packages Required
  • Environment
  • Example
  1. LaTeX

Code Snippet with Box in LaTeX

Insert code snippet with box using LaTeX

Previousx509 Certificate RenewalNext[gRPC] Generate .pb.go from .proto

Last updated 2 years ago

There are some times that you need to include code snippet using LaTeX. Just like markdown, there are ways of formatting a code snippet in a way that can be distinguished from a normal text.

This guide was made by using .

Packages Required

  • [newfloat]{minted}

  • {caption}

\usepackage[newfloat]{minted}
\usepackage{caption}

Environment

Change this accordingly

\newminted{code}{frame=lines,framerule=2pt}
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Code}

This will make \code as a code segment. With caption as Code.

Example

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[newfloat]{minted}
\usepackage{caption}

\newminted{code}{frame=lines,framerule=2pt}
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Code}

\begin{document}

\begin{code}
\begin{minted}[frame=single,framesep=10pt]{c}
#include <stdio.h>
int main(void) {
    printf("Hello World!\n");
    return 0;
}
\end{minted}
\captionof{listing}{Example Code in C: \texttt{hello\_world.c}}
\end{code}

\begin{code}
\begin{minted}[frame=single,framesep=10pt]{python}
if __name__ == "__main__":
    print("Hello World!)
\end{minted}
\captionof{listing}{Example Code in Python: \texttt{hello\_world.py}}
\end{code}


\end{document}

Will return

Using github.com/gijs-pennings/latex-homework will make #include as non italic.

Overleaf