Comments (5)
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 optionescapeinside=||
when inputting.- Vert
|
is used as delimiter, to reserve dollar$
for minted optionmathescape
. - The
\detokenize
is needed for allowing-
in label names, see #312.
- Vert
- for
firstnumber=<number>
, use an expandable way to extract the (Arabic) value of a label. That's what\getrefnumber{<label>}
fromrefcount
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}
from minted.
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.
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.
Yes, firstnumber=\getrefnumber{...}
works exactly as expected. Thank you!
from minted.
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)
- importing mathtools after minted gives errors in amsmath.sty HOT 2
- Passing additional flags to `pygmentize` / Using local lexers with the `-x` flag HOT 3
- "bgcolor" option is not in the right place in the documentation
- Only allow page break on a blank line HOT 2
- Trying to get `\inputminted` works with variable arguments HOT 14
- `\minted@opt@quote` prevents expansion too much HOT 5
- [Feature Request] Allow arbitrary or tagged line ranges HOT 1
- Passing newlines via `+v` argument causes error in 2.7 HOT 5
- Use a \def macro as the value for the style option HOT 3
- Update the options forwarded to `fvextra` HOT 1
- breakautoindent option doesn't work with some languages HOT 3
- Custom lexer no longer worked in my computer. HOT 6
- Make `langlinenos` with with `\inputminted` HOT 2
- `\mintinline{cpp}{#include}` in section title results in error HOT 12
- Leading Chinese characters introduce unexpected boxes HOT 5
- Didn't receive error message that fvextra was not installed HOT 2
- Minted ignores fontfamily setting HOT 4
- Font settings (migrating from lst-listings) HOT 12
- clearing `\verbatim@nolig@list` does not allow for code ligatures HOT 2
- Confused by arbitrary failure HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minted.