Re: Insert listing -- from file?

Bernt Lie via lyx-users <[email protected]> Wed, 4 Feb 2026 10:06:19 +0000
Newsgroups gmane.editors.lyx.general
Message-ID <OLAP279MB01525AD62B5B7D0C393395889C98A@OLAP279MB0152.NORP279.PROD.OUTLOOK.COM>
Thanks,


  *
Minted uses styles which you can set with the style option, in preamble

\AtBeginDocument{\setminted{style=name}}


Hm...

Inserting this command, and setting "style=default" produced the usual thing,

[cid:177de988-84d4-4f1e-b062-3bc26e05412c]

Changing to "style=colorful" produced a slight change, but not as expected,
[cid:7f4be5cf-0083-4a95-a861-a3328f648ebf]

I have used Google AI Studio to produce the preamble... Maybe AI Studio has messed up? Here is my preamble:

% ----------------------------------------
% My personal math package
% ----------------------------------------
\usepackage{C:/Users/Bernt/OneDrive/.../berntmath_mnt}


Two comments to the "berntmath_mnt.sty" file content (below)...

  1.
AI Studio added some code to make the boxes with drop shadow have equal width in the "listings" code and the "minted" code, and the same thickness of the drop shadow.
  2.
AI Studio added some code to "simplify" the insertion of the file name "JuliaUnicodeFile", but has not been able to figure out how to specify caption and label ― so maybe this "simplification" was a mistake.

My "berntmath_mnt.sty" file (I delete the math macros to make it shorter...):

% ============================================================
%  Bernt's Master Preamble: Final Unified Stable Integration
% ============================================================
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
\fi
\usepackage{amsmath, xcolor, listings, minted, nomencl, etoolbox}
\usepackage[most]{tcolorbox}
\tcbuselibrary{minted, listings, skins}

\AtBeginDocument{\setminted{style=default}}

% NOTE: Enable Index/Nomenclature in LyX Settings > Indexes & Nomenclature
\KOMAoptions{toc=index}

% --- Part 0: Global Font Setup ---
\ifXeTeX
  \usepackage{fontspec}
  \setmonofont{JuliaMono}[Contextals=Alternate, Scale=MatchLowercase]
\fi


% --- Part 3: Unified Julia Syntax Colors ---
\definecolor{juliakeyword}{RGB}{170, 0, 240}   % Purple
\definecolor{juliastring}{RGB}{230, 20, 20}    % Red
\definecolor{juliacomment}{RGB}{120, 120, 120} % Neutral Gray
\definecolor{juliafunction}{RGB}{230, 160, 0}  % Gold (range, plot, cos)
\definecolor{julianumber}{RGB}{0, 200, 40}     % Green

% --- Part 4: Julia Language Definition (For Listings) ---
\lstdefinelanguage{Julia}{
  morekeywords={abstract,break,case,catch,const,continue,do,else,elseif,end,export,false,for,function,immutable,import,importall,if,in,macro,module,otherwise,quote,return,switch,true,try,type,typealias,using,while,where,mutable,struct,primitive,local,global},
  morekeywords=[2]{println,print,sin,cos,tan,exp,log,sqrt,abs,max,min,plot,range,zeros,ones,collect,linspace,solve},
  morekeywords=[3]{pi,true,false,nothing,NaN,Inf},
  sensitive=true,
  morecomment=[l]{\#},
  morecomment=[n]{\#=}{=\#},
  morestring=[b]",
  morestring=[b]',
}

% --- Part 5: Global Listings Settings ---
\lstset{
    language=Julia, basicstyle={\ttfamily\small}, columns=flexible, keepspaces=true,
    keywordstyle=\color{juliakeyword}\bfseries,
    keywordstyle=[2]\color{juliafunction},
    keywordstyle=[3]\color{julianumber},
    stringstyle=\color{juliastring},
    commentstyle=\color{juliacomment}\itshape,
    numbers=left, numberstyle={\tiny\ttfamily\color{gray}}, stepnumber=1, numbersep=5pt, breaklines=true,
    literate={0}{{{\color{julianumber}0}}}1 {1}{{{\color{julianumber}1}}}1 {2}{{{\color{julianumber}2}}}1
             {3}{{{\color{julianumber}3}}}1 {4}{{{\color{julianumber}4}}}1 {5}{{{\color{julianumber}5}}}1
             {6}{{{\color{julianumber}6}}}1 {7}{{{\color{julianumber}7}}}1 {8}{{{\color{julianumber}8}}}1 {9}{{{\color{julianumber}9}}}1
             {π}{{$\pi$}}1 {ω}{{$\omega$}}1,
}

% --- Part 6: The Shared Shadow Box Style ---
\tcbset{JuliaShadowBox/.style={
    enhanced, width=\linewidth, sharp corners, colback=white, colframe=black, boxrule=0.7pt,
    shadow={2.5pt}{-2.5pt}{0pt}{black}, left=6mm, top=1mm, bottom=1mm, right=1mm, boxsep=0pt
}}

% --- Part 7: THE MAGIC HOOKS (Automatic Shadow-boxing for LyX) ---
\tcolorboxenvironment{lstlisting}{JuliaShadowBox}
\AtBeginDocument{
  \let\OldLstInputListing\lstinputlisting
  \renewcommand{\lstinputlisting}[2][]{%
    \begin{tcolorbox}[JuliaShadowBox]\OldLstInputListing[#1]{#2}\end{tcolorbox}
  }
}

% --- Part 8: FORCED COLOR SYNC (The "Internal Token" Method) ---
% \usemintedstyle{default} % Set the baseline


\newcommand{\JuliaUnicodeFile}[1]{%
    \tcbinputlisting{listing engine=minted, minted language=julia, listing file={#1}, listing only, JuliaShadowBox,
    minted options={fontsize=\small, linenos=true, numbersep=6pt, breaklines=true}}
}


Anyways, if anyone with some experience sees what is wrong, please let me know. (Both the color choice in minted that doesn't work, and the possibility to insert caption + label for minted code ― this works for listings code).

________________________________
From: lyx-users <[email protected]> on behalf of Jürgen Spitzmüller <[email protected]>
Sent: Wednesday, February 4, 2026 8:26 AM
To: [email protected] <[email protected]>
Subject: Re: Insert listing -- from file?

Am Dienstag, dem 03.02.2026 um 14:57 +0000 schrieb Bernt Lie via lyx-
users:
>    1. Where on earth does LyX with the minted package read the color
> specifications? Where/how can I changed them? (I have also tried to
> specify them in Preamble, but no success).

Minted uses styles which you can set with the style option, in preamble

\AtBeginDocument{\setminted{style=name}}

Available styles are here:
https://pygments.org/styles/

> I have a second problem, and that is how to insert caption and labels
> for the minted package.

If you insert the listing from a file: In the settings dialog of the
file/programlisting insert inset.

--
Jürgen
--
lyx-users mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-users

-- 
lyx-users mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-users
image.png (image/png, 68.9 KB) - not displayed
image.png (image/png, 70.3 KB) - not displayed