ka373

IT 관계자, 프로그래머를 위한 LaTeX 초보 팁 몇 가지 본문

03. 프로로 가는 길

IT 관계자, 프로그래머를 위한 LaTeX 초보 팁 몇 가지

ka373 2019. 11. 12. 22:40

글꼴: Courier

코드를 넣을 때 고려해볼 수 있는 글꼴

 

\usepackage{courier}

 

사용 시:

\texttt{쓰고 싶은 글자}

 

_______________________________

문서 내에 코드 넣기 1: verbatim 사용

한글도 잘 들어가니까 한글 슈도코드를 넣을 때 유용할 수 있음.

 

\usepackage{verbatim} 써준 후,

 

\begin{verbatim} 
#include 
printf("Hello world");
//가나다라 마바사
\end{verbatim}

 

직접 넣을 수도, 파일 이름으로 넣을 수도 있음

\verbatiminput{파일명}

이 때 파일명에 _가 들어가면 에러가 뜨는듯

_______________________________

문서 내에 코드 넣기 2: lstlisting 사용

https://scripting.tistory.com/796

글자 설정 예시: basicstyle = \footnotesize\ttfamily,

설정에 따라 컬러링도 됨

 

\usepackage{listings, chngcntr}
\usepackage{textcomp}      % lstlisting 따옴표 모양 유지

\renewcommand\lstlistingname{코드}

 

-코드 넣기: https://code-examples.net/ko/q/277972 참고

\begin{lstlisting}[escapechar=\%]
codeline1
codeline2
%
\end{lstlisting}

 

-일반 텍스트 파일 넣기: https://tex.stackexchange.com/questions/75324/lstinputlisting-for-a-normal-text-file 참고

언어란 비워두기

\lstinputlisting[language={}]{text.txt}

 

이런 방식으로 넣을 수도 있음

\begin{lstlisting}[language={}]

...

 

- 코드 넣기

\lstinputlisting[language={C}]{a_main.c}

 

_______________________________

lstlisting 사용 시 코드 내에 한글 넣기

다른 방법도 있을 수 있으나 그냥 나는 코드 내에 영어 쓸 일이 많아서

~한글~ 식으로 ~,~로 감싸줌

여러줄이면 줄마다 넣어줌?

참고: http://www.ktug.org/xe/index.php?mid=KTUG_QnA_board&document_srl=223503

http://faq.ktug.org/faq/SourceCodeListing#s-1.5.4

 

간단한 script로 소스코드에 영어가 아닌 부분이 있으면

%*,  *)으로 감싸주는 전처리를 했습니다?

http://www.ktug.org/xe/index.php?mid=KTUG_open_board&document_srl=177693

 

_______________________________

lstlisting 사용하여 코드 넣을 때 팁?

어디까지 개행 없이 코드를 넣을 수 있는지 너비를 자기가 알아볼 수 있게 표시해 두면 코드 입력시 편함

(다음 ■의 예시 참고)

 

_______________________________

lstlisting 사용 시 코드 내 특정 단어를 이탤릭체로 지정(1)

 

다음 코드를 삽입:

emph={class, def},    <- 단어 목록
emphstyle=\itshape

 

예를 들어 문법을 삽입할 때

실제 키워드는 정자로, 정의하는 문법은 이탤릭체로 지정할 때가 있다.

이 때 사용할 수 있다.

 

예시:

 

\begin{lstlisting}[
caption = 캡션, % '_' => '\_'
label = codelabel,
stringstyle         = \ttfamily,
emph={class, def},
emphstyle=\itshape
]%------------------------------------------------------------------<- 화살표까지 입력, 여기부터 코드, (한 줄 Enter 넣기)
~//코드~

\end{lstlisting}
%-------------------------------------------------------------------<-

 

 

참고: https://tex.stackexchange.com/questions/181307/use-textit-in-listing

 

_______________________________

lstlisting 사용 시 코드 내 특정 단어를 이탤릭체로 지정(2)

 

위에서 소개한 한글 삽입법과 비슷하게 할 수 있다.

 

~\textit{이탤릭체로 하고 싶은 글자}~

 

_______________________________

\lstset 설정 참고

 

https://src-bin.com/ko/q/146922d

 

_______________________________

 

Comments