I have some own commands (as \note) that I usually define in the beginning of each document, which I would like TeXmaker to highlight in the same way as similar commands such as sections and math are given own and distinct colors in the the .tex document when viewed in TeXmaker (i.e. I would like to be able to give my own commands colors distinct from those of other commands). Is this possible?
TeXmaker – Changing the Color of User Defined Commands
highlightingtexmaker
Related Solutions
The reason for this is the way environments in LaTeX work.
A \begin{...}
command starts a group, stores the environment name and then executes the environment start command.
A \end{...}
command checks that you are closing the right environment, executes the environment end command and closes a group.
A group has quite some effects, one of them being that non-global assignments to variables (and similar stuff like command definitions) inside it are revoked when the group is closed. Because of this, you usually don't want to load packages inside a group. (It might be that \usepackage
actually checks this.)
If you don't really want a group but just folding, I propose you have a look at your editor's configuration to see if you can use some comment structure which doesn't influence the actual code which LaTeX sees.
Otherwise, you might be able to do something similar like the document
environment does - in its start command, it starts with closing the group started by \begin
again, so there is no superfluous group. But then you might need to manage the current environment variable yourself so \end{folding}
doesn't give you an error. Have a look at source2e to see how the kernel does it.
A solution with hf-tikz
(requires two compilation runs):
\documentclass[dvipsnames]{article}
\usepackage{amsmath}
\usepackage[customcolors]{hf-tikz}
\definecolor{My}{RGB}{0,31,63}
\definecolor{MyConst}{RGB}{128,128,128}
\definecolor{MyFunc}{RGB}{0,75,107}
\definecolor{MyIndep}{RGB}{127,55,0}
\definecolor{MySubst}{RGB}{250,230,230}
\newcommand{\const}[1]{{\color{MyConst}\mathrm{#1}}} % normal constant
\newcommand{\uconst}[1]{\mathrm{#1}} % universal mathematical constant
\newcommand{\var}[1]{{\color{MyIndep}#1}} % independent variable
\newcommand{\subst}[1]{{\colorbox{MySubst}#1}} % substitution
\hfsetfillcolor{Lavender!50}
\hfsetbordercolor{white}
\begin{document}
\[
\color{My}
{\color{MyFunc}\Psi} =
\const{\Psi_{_0}}\;
\uconst{e}^{\uconst{i} \left(
\tikzmarkin{a}(0.01,-0.175)(-0.015,0.3)\frac{p}{\const{\hbar}}\tikzmarkend{a}
\var{x} - \tikzmarkin{b}(0.01,-0.175)(-0.015,0.3)\frac{E}{\const{\hbar}}\tikzmarkend{b}\var{t} \right) }
\]
\end{document}
The result:
Remarks:
- it is better to use
\[ \]
rather than$$ $$
; - the package allows you to not set in math mode the text inside a
\colorbox
: one just have to declare where the delimiters of the box should be positioned.
From version 0.3 of the package, things are a bit more user-friendly as shown in hf-tikz doesn't box around equation. The above code can be written thanks to styles as:
\documentclass[dvipsnames]{article}
\usepackage{amsmath}
\usepackage[customcolors]{hf-tikz}
\definecolor{My}{RGB}{0,31,63}
\definecolor{MyConst}{RGB}{128,128,128}
\definecolor{MyFunc}{RGB}{0,75,107}
\definecolor{MyIndep}{RGB}{127,55,0}
\definecolor{MySubst}{RGB}{250,230,230}
\newcommand{\const}[1]{{\color{MyConst}\mathrm{#1}}} % normal constant
\newcommand{\uconst}[1]{\mathrm{#1}} % universal mathematical constant
\newcommand{\var}[1]{{\color{MyIndep}#1}} % independent variable
\newcommand{\subst}[1]{{\colorbox{MySubst}#1}} % substitution
% available from version 0.3
\tikzset{offset def/.style={
above left offset={-0.015,0.3},
below right offset={0.01,-0.175},
},
hl/.style={
offset def,
set fill color=Lavender!50,
set border color=white,
}
}
\begin{document}
\[
\color{My}
{\color{MyFunc}\Psi} =
\const{\Psi_{_0}}\;
\uconst{e}^{\uconst{i} \left(
\tikzmarkin[hl]{a}\frac{p}{\const{\hbar}}\tikzmarkend{a}
\var{x} - \tikzmarkin[hl]{b}\frac{E}{\const{\hbar}}\tikzmarkend{b}\var{t} \right) }
\]
\end{document}
Procedure to get .png output
After reading the comments below, here is a way to get a .png
. The standalone
class here really helps since it has a png
class option.
Save as test.tex
:
\documentclass[dvipsnames,png, border=2pt]{standalone}
\usepackage{amsmath}
\usepackage[customcolors]{hf-tikz}
\definecolor{My}{RGB}{0,31,63}
\definecolor{MyConst}{RGB}{128,128,128}
\definecolor{MyFunc}{RGB}{0,75,107}
\definecolor{MyIndep}{RGB}{127,55,0}
\definecolor{MySubst}{RGB}{250,230,230}
\newcommand{\const}[1]{{\color{MyConst}\mathrm{#1}}} % normal constant
\newcommand{\uconst}[1]{\mathrm{#1}} % universal mathematical constant
\newcommand{\var}[1]{{\color{MyIndep}#1}} % independent variable
\newcommand{\subst}[1]{{\colorbox{MySubst}#1}} % substitution
\hfsetfillcolor{Lavender!50}
\hfsetbordercolor{white}
\begin{document}
$
\color{My}
{\color{MyFunc}\Psi} =
\const{\Psi_{_0}}\;
\uconst{e}^{\uconst{i} \left(
\tikzmarkin{a}(0.01,-0.175)(-0.015,0.3)\frac{p}{\const{\hbar}}\tikzmarkend{a}
\var{x} - \tikzmarkin{b}(0.01,-0.175)(-0.015,0.3)\frac{E}{\const{\hbar}}\tikzmarkend{b}\var{t} \right) }
$
\end{document}
and compile with:
pdflatex -shell-escape test.tex
This will create
- test.pdf
- test.png
perfectly cropped.
Best Answer
\begin{customenvironment}.... \end{customenvironment}
can be added using Texmaker menu --> User-->User tags-->Edit User tags\note[]{}
can be added using Texmaker menu--> User--> Customize completion. In Customize completion dialog box type\note[@]{@}
--> Press add-->Ok (@
brings a vacant.
to replace with command options)Sometimes it may need a restart of Texmaker for user tags.
For more texmaker documentation go through this
http://www.xm1math.net/texmaker/doc.html#SECTION33