69

Here is the template I use for matlab code: \documentclass{article} \usepackage{listings} \usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white \definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue \definecolor{mylilas}{RGB}{170,55,241} \begin{document} \lstset{language=Matlab,% %basicstyle=\color{red}, ...


69

For typesetting Matlab code in LaTeX, consider using the matlab-prettifier package. Piggybacking on the listings package, it doesn't require much configuration, and it keeps track of the context (behind the scenes) in order to highlight code as it appears in the Matlab editor. In this respect, it arguably does a much better job than the other available ...


60

Here's a list of other possible solutions A solution that admits page breaks using mdframed: \documentclass{article} \usepackage[framemethod=tikz]{mdframed} \usepackage{lipsum} \begin{document} \lipsum[4] \begin{mdframed}[hidealllines=true,backgroundcolor=blue!20] \lipsum[2] \end{mdframed} \lipsum[4] \end{document} The environments provided by the ...


47

You can use the bclogo and/or mdframed and or tcolorbox packages. The main difference is that boxes produced using mdframed or tcolorbox might allow page breaks. A little example; the first box was produced using bclogo; the second one, using mdframed; the third one (similar to the second one) and the fourth one were produced using tcolorbox: \...


46

You could use TikZ, and the fit library for creating nodes fitting the desired area, a style for the highlighted node, so separated from the code and easy to change, the TikZ options overlay and remember picture, so you can later refer to those nodes, for example for drawing arrows and annotations later. To demonstrate why it's useful to have nodes for ...


44

To highlight the section of the next slides in a ToC you need to start the section officially using \section and then use \tableofcontents[currentsection] in a frame: \section{Foobar} \frame{\tableofcontents[currentsection]} There is also other options to \tableofcontents[<option>], like currentsubsection and hideallsubsections as well, all of them ...


44

I recommend TikZ. The result: The code: \documentclass{article} \usepackage{amsmath} \usepackage{tikz} \usetikzlibrary{arrows,matrix,positioning} \begin{document} \begin{tikzpicture} \matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m) { 8 &8 &1 &6 \\ 3 &8 &5 &...


42

I'm answering because I think there's a quite good solution on the problem. First of all I'd like to thank Andrew Stacey because without the discussion in chat I wouldn't be able to solve this and, more important, he founds the major issue in the code. What I learnt The answer to the question: Is there a way to automatically recognize the node angle a ...


38

I use the glossaries package for this purpose. It is very flexible, and allows you to define terminology, specify how it should look upon first and subsequent uses, and then produce a glossary of the words. Here is a simple example that displays the first term in italics, and uses hyperref to link the use of the terms to the definition in the glossary (...


38

Using Luatex, you can insert color literals to highlight ligatures. Save this snippet as color-ligatures.lua: documentdata = documentdata or { } documentdata.color_ligatures = { } local color_ligatures = documentdata.color_ligatures color_ligatures.color = { r = 0xee/255, g = 0x31/255, ...


35

You can use \tikzmark from this answer by Andrew Stacey to mark the endpoints where you want the box. This allows you to do the matrix in the usual way (outside of tikz). Since this is very similar to Werner's solution that used pstricks, I adapted that code to use \tikzmark: Notes: This does require two runs: the first to compute the positions of the ...


35

You can't do this in a fully automated way. It's not possible to give a list of words and get TeX recognize the first occurrence. What you can do is to mark the terms in the .tex file, after giving the list and something like the following code: \documentclass{article} %%% Code to set up special term treatment \makeatletter \newcommand{\specialterms}[1]{% ...


34

The piecewise uncovering is described in §23 of the beamer user guide ("How to Uncover Things Piecewise"). To have the not (yet) uncovered items "dimmed" instead of invisible, you just need to combine this with a respective "transparency effect", discussed in §17.6 ("Transparency Effects"). The \setbeamercovered{transparent} can also be applied outside ...


34

Here'a an initial version using the soul, marginnote and tikz packages (and, as it has become customary, the ubiquitous \tikzmark): \documentclass{article} \usepackage{soul} \usepackage{marginnote} \usepackage{tikz} \usetikzlibrary{calc} \definecolor{HLcolor}{RGB}{124,18,18} \sethlcolor{HLcolor!20} \makeatletter \newdimen\SOUL@dimen %new \def\SOUL@...


34

You can (ab)use \soulregister with the identifier 7. While this command is meant to be used to register font switching commands (with identifier 0 or 1), a look in the implementation part of the documentation reveals that it also accepts other numbers: 9 for accents, 8 for \footnote and, the one that's interesting here, 7 for "\textsuperscript or similar ...


33

\documentclass{article} \usepackage{xcolor} \begin{document} ~\\ \colorbox{pink}{highlight}\\ \colorbox{green}{highlight}\\ \colorbox{yellow}{highlight}\\ \bfseries\colorbox{pink}{highlight + boldface}\\ \colorbox{green}{highlight + boldface}\\ \colorbox{yellow}{highlight + boldface}\\ \color{red}\colorbox{pink}{highlight + boldface + colored text}\\ \...


31

It's almost a year later, but as the OP has not yet accepted an answer, I still see my chance :-) In the following, I use the same basic principle as in my other answer, that is, employ listings moredelim=** option to define delimiters, which styles then apply on top of all other formattings, so that the syntax formatting is kept. However, instead of being ...


31

The mcode package still supports Matlab code formatting, setting the default lstlisting environment (from listings) formatting to that of Matlab. It also provides \mcode{<code>} for inline Matlab code. \documentclass{article} % http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package \usepackage[framed,numbered,autolinebreaks,...


31

There are some packages that can help you, for example: empheq hf-tikz and along this site some answers could be a good starting point: Highlight an equation within an align environment Highlight an equation within an align environment with color option Black and white emphasis for \boxed? Here, I provide you a MWE using the hf-tikz package. Actually \...


30

Here is a solution using TikZ. You may also want to read the solution suggested by percusse in his comment, although I think my solution is simpler to understand for a newcommer to TikZ. comment: My original solution included an align command in the matrix, this actually turned everything in the matrix into text, not math stuff. I removed the align ...


28

You can just do this with the listings package, and you won't even need an external pre-processor. listings doesn't come with a diff style but you can define one like this: \lstdefinelanguage{diff}{ morecomment=[f][\color{blue}]{@@}, % group identifier morecomment=[f][\color{red}]-, % deleted lines morecomment=[f][\color{green}]+, % ...


28

Perhaps you have set a language using \lstset. You can disable the language by using the empty language: \lstinputlisting[language={}]{file.txt}


26

Here's a method that uses only LaTeX's "built-in" commands \cline and \multicolumn to create the frame around the upper-left 3x3 submatrix. By the way, because your matrix has more than 10 columns, I believe it's necessary to either use the array environment instead of the bmatrix environment (bmatrix is essentially a "wrapper" around the array construct) ...


26

Another approach always using TikZ. Since the backgrounds library was not exploited so far, I made use of it; first I defined two commands that allow to fill the background of the elements highlighted or not: \NewDocumentCommand{\highlight}{O{blue!40} m m}{% \draw[mycolor=#1] (#2.north west)rectangle (#3.south east); } \NewDocumentCommand{\fhighlight}{O{...


25

I think the best solution was already provided by Claudio. I am only putting this here to do something about that \boxed command. But I think this solution will not work with split environment so this does not really answer your question. As pointed out already, you may better use the solution by Claudio or use empheq package instead. Here is what I came up ...


24

The suggested and accepted answer does not work correctly as the \captionof command requires to be inside an environment. This is pointed out in the caption documentation. For example in my case there was no proper vertical space after the caption. A proper solution is to define a new environment: \usepackage{caption} % ... \newenvironment{code}{\...


24

If figured that I can adjust my code written for Test if a paragraph has a page break in it? to do underlining and also highlighting. This solution marks the begin and the end of the text with both TikZ and zref marker (the latter to test for page breaks) and draws the lines using tikz between the markers. The current line width is taken into account and new ...


24

Use \tikzmark to place auxiliary nodes and the fit library, together with the remember picture, overlay options to place the shadings. A little example: \documentclass{beamer} \usepackage[ruled,vlined,linesnumbered]{algorithm2e} \usepackage{tikz} \usetikzlibrary{fit,calc} \newcommand{\tikzmark}[1]{% \tikz[overlay,remember picture,baseline] \node [anchor=...


Only top voted, non community-wiki answers of a minimum length are eligible