Method: MaRuKu::Out::Latex#to_latex_code

Defined in:
lib/maruku/output/to_latex.rb

#to_latex_codeObject

Attribute: latex_use_listings Scope: document Output: latex Summary: Support for ‘listings` package. Related: code_show_spaces, code_background_color, lang, code_lang

If the ‘latex_use_listings` attribute is specified, then code block are rendered using the `listings` package. Otherwise, a standard `verbatim` environment is used.

* If the ‘lang` attribute for the code block has been specified, it gets passed to the `listings` package using the `lstset` macro. The default lang for code blocks is specified through the `code_lang` attribute.

lstsetlanguage=ruby

Please refer to the documentation of the ‘listings` package for supported languages.

If a language is not supported, the ‘listings` package will emit a warning during the compilation. Just press enter and nothing wrong will happen.

* If the ‘code_show_spaces` is specified, than spaces and tabs will be shown using the macro:

lstsetshowspaces=true,showtabs=true

* The background color is given by ‘code_background_color`.



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/maruku/output/to_latex.rb', line 251

def to_latex_code;
	raw_code = self.raw_code
	
	if get_setting(:latex_use_listings)
		@doc.latex_require_package('listings')
			
		s = "\\lstset{columns=fixed,frame=shadowbox}"

		if get_setting(:code_show_spaces) 
			s+= "\\lstset{showspaces=true,showtabs=true}\n"
		else
			s+= "\\lstset{showspaces=false,showtabs=false}\n"
		end
		
		color = latex_color get_setting(:code_background_color)
		
		s+= "\\lstset{backgroundcolor=#{color}}\n" 
		
		s+= "\\lstset{basicstyle=\\ttfamily\\footnotesize}\n" 
		
		
		lang = self.attributes[:lang] || @doc.attributes[:code_lang] || '{}'
		if lang
			s += "\\lstset{language=#{lang}}\n"
		end
		
		"#{s}\n\\begin{lstlisting}\n#{raw_code}\n\\end{lstlisting}"
	else
		"\\begin{verbatim}#{raw_code}\\end{verbatim}\n"
	end
end