1
$\begingroup$

I have posted this question

\documentclass[12pt]{article}
\usepackage{listings,xcolor}
\ProvidesPackage{latexalpha2Win}
\lstset{language=Mathematica}
\lstset{basicstyle={\sffamily\footnotesize},
    numbers=left,
    numberstyle=\tiny\color{gray},
    numbersep=5pt,
    breaklines=true,
    captionpos={t},
    frame={lines},
    rulecolor=\color{black},
    framerule=0.5pt,
    columns=flexible,
    tabsize=2
}
\begin{document}
    \begin{lstlisting}[breaklines]
        SolveValues[Sqrt[8  x^2 - 3  x - 10] == -2 + 3  x, x, Reals]
    \end{lstlisting}
\end{document}

enter image description here

The keyword SolveValues not bold. I input morekeywords={SolveValues} by hand in LaTeX. How can I tell Mathematica update new Keywords.

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Just add morekeywords={SolveValues} in the definition?

in this list you can manually add other ones. The definition is done only one time. You can save that in the preamble. So you only need to add it one time. Other than this, you have to edit the listings style file itself which contains the language=Mathematica default settings.

But why do that? it is just as easy to add morekeywords={SolveValues} in your preamble.

\documentclass[12pt]{article}
\usepackage{listings,xcolor}
\ProvidesPackage{latexalpha2Win}
\lstset{language=Mathematica}
\lstset{basicstyle={\sffamily\footnotesize},
    numbers=left,
    numberstyle=\tiny\color{gray},
    numbersep=5pt,
    breaklines=true,
    captionpos={t},
    frame={lines},    
    rulecolor=\color{black},
    framerule=0.5pt,
    columns=flexible,
    tabsize=2,
    morekeywords={SolveValues}
}
\begin{document}
    \begin{lstlisting}[breaklines]
        SolveValues[Sqrt[8  x^2 - 3  x - 10] == -2 + 3  x, x, Reals]
    \end{lstlisting}
\end{document}

gives

enter image description here

Btw, it is better to define listing style. This way you can have different styles for different languages within the same document without them clashing with each others. Like this

\documentclass[12pt]{article}
\usepackage{listings,xcolor}
\ProvidesPackage{latexalpha2Win}

\lstdefinestyle{MMA}{%
    language=Mathematica,%
    breaklines=true,
    basicstyle={\sffamily\footnotesize},
    numbers=left,
    numberstyle=\tiny\color{gray},
    numbersep=5pt,
    breaklines=true,
    captionpos={t},
    frame={lines},    
    rulecolor=\color{black},
    framerule=0.5pt,
    columns=flexible,
    tabsize=2,
    morekeywords={SolveValues}
}

\lstnewenvironment{MMA}{%
  \lstset{style=MMA}}{}


\begin{document}
    \begin{MMA}
        SolveValues[Sqrt[8  x^2 - 3  x - 10] == -2 + 3  x, x, Reals]
    \end{MMA}
\end{document}

In my env. I have 10 different custom listing styles for 10 different languages. (Fortran, C++, Java, Maple, etc...)

$\endgroup$
3
  • $\begingroup$ I hope, your code can update new keywords automatically. In this code VectorAngle and InfinitePlane not bold. I must input by hand. \begin{MMA} Clear["Global`*"]; aa = {0, 0, 0}; bb = {a, 0, 0}; c = {a, a, 0}; d = {0, a, 0}; s = {0, 0, h}; u = Cross[s - bb, s - c]; v = Cross[s - aa, s - c]; SolveValues[VectorAngle[u, v] == Pi/3, h, Reals, Assumptions -> {a > 0, h > 0}] SAB = InfinitePlane[{s, aa, bb}]; \end{MMA} $\endgroup$ Commented May 8 at 4:39
  • $\begingroup$ @JohnPaulPeter You have to add these morekeywords={SolveValues,VectorAngle,InfinitePlane} basically you have to do it once. How else will listing know which to make bold and which is not? Someone has to tell it. If it is not in the style file itself. Since Mathematica with each new version adds more new commands, only way to do it, is to update the list. My Maple list is 3 pages long of keywords. $\endgroup$
    – Nasser
    Commented May 8 at 4:55
  • $\begingroup$ Thank you for your comment. $\endgroup$ Commented May 8 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.