Q&A 마당은 텍 관련 질문/답변을 위해 만들었습니다.
- 로그인 없이 자유롭게 글을 읽고 쓸 수 있는 철학은 처음과 같이 계속됩니다.
- 질문 전에 아래를 읽어 보세요. 좋은 질문이 좋은 답을 받을 수 있는 좋은 방법입니다.
- 질문에 맞는 제목을 붙이세요. 질문의 내용과 관련없는 "고수님", "긴급질문", "도와주세요"와 같은 제목은 답이 잘 올라오지 않습니다. 이 게시판에 올라오는 모든 글은 질문입니다. 굳이 [질문], [Q]를 적으실 필요도 없습니다.
- 내용을 충실히 적어 주시고, 같은 상황을 재현할 수 있는 최소한의 예제가 같이 있어야 합니다.
- 최소 예제는 "Minimal working example"을 읽어 보세요.
- 파일을 첨부하실 때에는 가능한 압축하여 파일 크기를 줄여서 올려주시길 바랍니다.
- 개인적으로 사용하신 글꼴이 들어 있는 경우, preparefont.sty에 관한 답변을 참조하세요.
- 스팸 글을 막기 위하여 짧은 시간 내에 다시 글이 등록되는 IP를 막거나, 광고 글을 막기 위하여 금지어로 .com, .net 등을 설정하고 있습니다. 다소간의 불편함이 있으시더라도 양해 바랍니다.
- 금지어에서 stackexchange, stackoverflow, ctan, overleaf, , github, google.com, gmail.com, .org, .io, sil.org, wiki.com, tistory.com등은 해제하였습니다.
- MathJax를 이용한 수식조판을 사용하실 수 있습니다. 여기를 참조하세요.
- 사용하는 편집기는 CKeditor입니다.
- 편집기에서 [enter]를 누르면 <p> 태그가 들어가고, 문단으로 생각하고 한 줄을 비웁니다.
- 글줄만 바꾸려면 [shift-enter]를 누르면 <BR> 태그가 들어가므로 용도에 맞게 나누어 쓸 수 있습니다.
- 수식를 문서내에 삽입하시려면 에디터를 툴바에서 [소스]를 눌러 HTML로 입력할 수 있게 바꾸신 후 <pre> </pre> tag를 사용하셔서 <pre> 여러 줄의 수식 </pre>처럼 입력하시면 좋습니다.
listing 패키지의 한글 주석 색넣기
2017.02.15 11:44
안녕하세요.
TeX의 listing 패키지를 사용하던 중..
한글 코맨트가 색이 칠해지지 않아 어찌해결 할까 고민중 도움을 받고자 글을 올리게 되었습니다.
\documentclass[a4paper,footnote]{oblivoir}
\pagestyle{hangul}
%\usepackage[default]{memucs-interword-x}
%\interhword{.4}{.1}{.1}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{caption}
\usepackage{geometry}
\usepackage{color}
\usepackage{fontspec}
\usepackage{vhistory}
\newfontfamily{\ttconsolas}{Consolas}
\setmainfont[Mapping=tex-text]{TeX Gyre Termes}
\setsansfont[Mapping=tex-text]{TeX Gyre Heros}
\setkormainfont(NanumBarunGothicBold){NanumBarunGothic}
\setkorsansfont(NanumGothicExtraBold)(NanumGothicBold){NanumGothic}
\definecolor{codekeyword}{rgb}{0.34,0.61,0.84}
\definecolor{codecomment}{rgb}{0.34,0.65,0.29}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstset{
commentstyle=\color{codecomment}\textit,
keywordstyle=\color{codekeyword}\textbf,
numberstyle=\small\color{codegray},
stringstyle=\color{codepurple},
frame=top,frame=bottom,
basicstyle=\small\normalfont\ttconsolas,
stepnumber=1,
numbers=left,
numbersep=10pt,
tabsize=2,
extendedchars=true,
breaklines=true,
captionpos=t,
mathescape=true,
stringstyle=\color{white}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=17pt,
framexbottommargin=5pt,
framextopmargin=5pt,
showstringspaces=false
}
\DeclareCaptionFormat{listing}{\rule{\dimexpr\textwidth+17pt\relax}{0.4pt}\par\vskip1pt#1#2#3}
\captionsetup[lstlisting]{format=listing,singlelinecheck=false, margin=0pt, font={sf},labelsep=space,labelfont=bf}
\renewcommand\lstlistingname{Example}
\begin{document}
\begin{lstlisting}[language=C++,caption={테스트입니다. 하이하이},escapeinside=`']
#include <tuple>
#include <iostream>
#include <array>
#include <utility>
// Convert array into a tuple
template<typename Array, std::size_t... I>
decltype(auto) a2t_impl(const Array& a, std::index_sequence<I...>)
{
return std::make_tuple(a[I]...);
}
template<typename T, std::size_t N, typename Indices = std::make_index_sequence<N>>
decltype(auto) a2t(const std::array<T, N>& a)
{
return a2t_impl(a, Indices());
}
// pretty-print a tuple
// comment `한글 주석 스페이스도 안되나?' dmdm
template<class Ch, class Tr, class Tuple, std::size_t... Is>
void print_tuple_impl(std::basic_ostream<Ch,Tr>& os,
const Tuple & t,
std::index_sequence<Is...>)
{
using swallow = int[]; // guarantees left to right order
(void)swallow{0, (void(os << (Is == 0? "" : ", ") << std::get<Is>(t)), 0)...};
}
template<class Ch, class Tr, class... Args>
decltype(auto) operator<<(std::basic_ostream<Ch, Tr>& os,
const std::tuple<Args...>& t)
{
os << "(";
print_tuple_impl(os, t, std::index_sequence_for<Args...>{});
return os << ")";
}
int main()
{
std::array<int, 4> array = {1,2,3,4};
// convert an array into a tuple
auto tuple = a2t(array);
static_assert(std::is_same<decltype(tuple),
std::tuple<int, int, int, int>>::value, "");
// print it to cout
std::cout << tuple << '\n';
}
\end{lstlisting}
\end{document}
로 작성하였습니다..
도움을 주시면 감사하겠습니다.
댓글 9
-
김소원
2017.02.15 11:51
-
Progress
2017.02.15 13:07
일단 codecomment 색깔이 한글에도 나와야한다는 말씀인 것으로 이해하겠습니다.
색상 정의 이후에 한글 모노스페이스 폰트에 색깔을 넣으시면 어떨까요? 향후 한글 모노스페이스드 폰트, 즉 \ttfamily에는 모두 codecomment 색깔이 적용됩니다.\definecolor{codecomment}{rgb}{0.34,0.65,0.29}
... (이후에)
\setmonohangulfont{NanumGothicCoding}[Color=codecomment]
-
DohyunKim
2017.02.15 13:51
또는 listings 옵션에
texcl=true
를 넣어보세요. 이탤릭 효과가 사라지는 부작용이 있지만 한글에도 색깔이 들어갈 걸로 생각합니다.
-
DohyunKim
2017.02.15 14:33
이탤력은 \textit 가 아니라 \itshape 로 지시해야 하는 듯 하네요.
-
김소원
2017.02.20 10:25
감사합니다. itshape로 변경하였습니다.
texcl = true로 하니까 이텔릭체도 유지가 되면서 한글 폰트가 재대로 나오고 있습니다.
한글폰트도 mono폰트로 하고 싶은데 이것이 잘 안되고있네요.. -
Progress
2017.02.15 14:45
\textit 말고도 좀 몇 가지 고칠게 많아 보이긴 합니다.
- \usepackage[utf8]{inputenc}
- commentstyle=\color{codecomment}\textit,
+ commentstyle=\color{codecomment}\itshape,
- keywordstyle=\color{codekeyword}\textbf,
+ keywordstyle=\color{codekeyword}\bfseries,- extendedchars=true,
% 이 옵션은 아예 없애버리세요. 다국어지원과 관련하여 inputenc 패키지 따위와 섞어 쓰는 건데 우리와는 상관 없는 듯. -
김소원
2017.02.20 10:27
댓글 감사드립니다.
지적해주신 대로 전부 적용하였습니다.
한글 주석을 위해 나눔고딕코딩을 적용하려 하고 있습니다..
하지만 \setmonohangulfont{NanumGothicCoding}[Color=codecomment] 를 사용해 보았으나
XeLaTeX, LuaLaTeX 둘다 폰트를 찾을 수 없는지 컴파일이 되지 않고 있습니다.
해결 방법이 있겠습니까? -
김소원
2017.02.20 10:29
아 폰트를 못찾는것이 아니라 [Color=codecomment]가 먹히지 않고 있었던 것이네요.
\setmonohangulfont{NanumGothicCoding}
이것만으로는 색도 폰트도 적용되지 않는것 같습니다. -
김소원
2017.02.20 10:36
부분적으로 해결하였습니다.
lstset에 texcl=true로 지정해주고
\setmonofont{Consolas}
\setmonohangulfont{NanumGothicCoding}
를 해주었습니다.
다만 Consolas와 NanumGothicCoding이 서로 맞지 않네요.. 간격이 ..
monofont도 NanumGotiicCoding으로 맞춰주면 문제 없습니다만.. 영어 폰트는 Consolas로 하면서 간격을 맞출 방법은 없을까요?
일단은 `\color{codecomment}한글 주석 스페이스도 안되나?' 식으로 주석마다 다 붙여야 할 것 같은데.. 일일히 하지 않아도 될 방법이 없겠습니까?