Giter VIP home page Giter VIP logo

Comments (5)

muzimuzhi avatar muzimuzhi commented on September 17, 2024 2

It's always recommended to provide a small but complete example so others can just copy and test, rather than code snippets only.

Several steps are needed:

  • for foo.js, use |\label{\detokenize{<label>}}| to add a label, then use minted option escapeinside=|| when inputting.
    • Vert | is used as delimiter, to reserve dollar $ for minted option mathescape.
    • The \detokenize is needed for allowing - in label names, see #312.
  • for firstnumber=<number>, use an expandable way to extract the (Arabic) value of a label. That's what \getrefnumber{<label>} from refcount package for. Note \ref(*) is not expandable.

Full example. I deliberately make the value of label different from 1, so it's easier to check if firstnumber=\getrefnumber{...} works.

\begin{filecontents}[noheader,force]{foo.js}
function foo() {
} |\mintlabel{marker-from-foo-js}|
\end{filecontents}

\documentclass{article}
\usepackage{minted}
\usepackage{refcount}

\newcommand\mintlabel[1]{%
  \label{\detokenize{#1}}%
}

\begin{document}
Use the value of label \verb|marker-from-foo-js| in setting \verb|firstnumber=<number>|
\begin{minted}[autogobble, firstnumber=\getrefnumber{marker-from-foo-js}, linenos]{javascript}
  function foo() {
  }
\end{minted}

Typeset \verb|foo.js| which defines label \verb|marker-from-foo-js|
\inputminted[escapeinside=||, linenos]{javascript}{foo.js}
\end{document}

image

from minted.

muzimuzhi avatar muzimuzhi commented on September 17, 2024 1

Not possible until you apply some patch, for example one of the two redefinitions below. Note the original definitions live in fvextra.sty.

\makeatletter
% either expand value of `highlightlines` by \edef. This is more useful than the second one.
% before: \define@key{FV}{highlightlines}{\def\FV@HighlightLinesList{#1}}
\define@key{FV}{highlightlines}{\edef\FV@HighlightLinesList{#1}}

% or remove the \detokenize which disables expansion for #1. Is this \detokenize ever required?
\def\FV@HighlightLinesParse@Single#1{%
  % before: \expandafter\let\csname FV@HighlightLine:\detokenize{#1}\endcsname\relax
  \expandafter\let\csname FV@HighlightLine:#1\endcsname\relax}
\makeatother

from minted.

muzimuzhi avatar muzimuzhi commented on September 17, 2024 1

Hi, is it possible to have the similar function for highlightlines?

\inputminted[escapeinside=||, linenos, highlightlines={\getrefnumber{marker-in-foo-js}}]{javascript}{foo.js}

This doesn't work for me.

Just found this was once asked and answered (by myself) two years ago (Jun 2020) on tex-sx: https://tex.stackexchange.com/a/549882 .

from minted.

duzy avatar duzy commented on September 17, 2024

Yes, firstnumber=\getrefnumber{...} works exactly as expected. Thank you!

from minted.

duzy avatar duzy commented on September 17, 2024

Hi, is it possible to have the similar function for highlightlines?

\inputminted[escapeinside=||, linenos, highlightlines={\getrefnumber{marker-in-foo-js}}]{javascript}{foo.js}

This doesn't work for me.

from minted.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.