Closed Heziode closed 4 months ago
Your example doesn't reproduce your screenshot. Some font setting and perhaps minted
setting are missing.
\DeclareTotalTCBox{\CodeInline}{ O{text} v }{% verbatim, breakable, % Allow for line breaks ... }
First, the /tcb/breakable
option only enables page breaking in between tcolorbox
es, and has nothing to do with line breaking in the middle of inline boxes created by \tcbox
and derived commands, thus also the boxes defined with \NewTotalTCBox
.
That's said, total boxes defined with \NewTotalTCBox
cannot break into lines.
Decoration of arbitrary text (e.g., text consists of verbatim) which may span multiple lines and even multiple pages is hard in classic (non-LuaTeX) TeX engines. The general idea is to get positions and/or geometries of each broken text line and then add decorations to each of them. The decoration ranges from simple \rule
to complex tikzpicture
and even \tcbox
.
soul
or soulpos
package, see TeX-SX question Cool Text Highlighting in LaTeX, other TeX-SX questions linked to it, and #223.lua-ul
package provides the most satisfying result, but it's LuaTeX-only. See an example of lua-ul
and \mintinline
in this TeX-SX answer. Your example doesn't reproduce your screenshot. Some font setting and perhaps
minted
setting are missing.
I updated the code to have a MWE. Only the font differ, but I also tested like this with the default font, and the problem is still here.
Thank you for the clarification. Since I use lualatex, I will take a look at lua-ul
.
I close the issue, since a detailed answer has been given.
Here is my solution, based on the post:
\documentclass[12pt]{article}
\usepackage{minted}
\usepackage{iftex} % Used to check the engine used
\usepackage{xpatch} % Used to patch highlight depending of the engine used
\usepackage{xcolor} % To use custom colors :P
\usepackage{lua-ul} % Package for underlining text in LuaLaTeX
\usepackage{luacolor} % Required by lua-ul since we use custom colors
% Define a color for the inline code background
\definecolor{bg}{HTML}{e5e7eb}
\setmintedinline{breaklines,breakanywhere=true,bgcolor=bg}
% Define the command CodeInline with optional language parameter
\newcommand{\CodeInline}[2][text]{%
% Display code inline with backticks
\texttt{\`{}}\mintinline{#1}{#2}\texttt{\`{}}%
}
% Define custom highlighting command using lua-ul (if LuaLaTeX engine is used)
\makeatletter
\newcommand\myhl[2]{\highLight[#1]{#2}}
% Patch minted's inline code display to use custom highlighting
\xpatchcmd{\minted@inputpyg@inline}{%
\colorbox%
}{%
\myhl%
}{\typeout{Success}}{\fail}
\makeatother
\begin{document}
Eum eligendi veritatis est omnis beatae velit est ipsam explicabo quis quia animi. Reiciendis dolor modi omnis ipsum adipisci quo ducimus. Dolores sequi mollitia est deserunt quia doloribus fugit ut pariatur voluptas ut perspiciatis iure. Maiores qui nulla est aut modi. Unde occaecati. incidunt dolor velit dolorum voluptas possimus excepturi voluptatum. Dolores qui numquam ipsa quia totam animi explicabo quisquam qui iste illum esse ipsam labore odit. Impedit quo nisi labore voluptatem \CodeInline{/path/to/file.ext:123:4:TYPE/path/to/file.ext:123:4:TYPE} aut deserunt dolorum quidem. Omnis dolorum sapiente et occaecati labore dicta fuga. Laborum reiciendis consequatur rerum ex molestias voluptates autem et. Magnam numquam minima illo magnam. \mintinline{text}{/path/to/file.ext:123:4:TYPE/path/to/file.ext:123:4:TYPE} Quisquam quos eos in non ullam aut aperiam. Voluptas quo quia dolores quis ipsa velit odio consequuntur laboriosam cum. Illo pariatur molestiae tempora voluptatibus autem cum pariatur aperiam ipsa ipsa ut labore. Ut temporibus voluptatibus quos architecto perspiciatis. Quia non porro quaerat maiores vero saepe facere aut occaecati consequatur est et voluptate quasi. Qui sunt dolor deleniti aut qui.
\end{document}
This produce the following result:
% Define the command CodeInline with optional language parameter \newcommand{\CodeInline}[2][text]{% % Display code inline with backticks \texttt{\`{}}\mintinline{#1}{#2}\texttt{\`{}}% }
You may want to grab the inline code in verbatim, \NewDocumentCommand{\CodeInline}{ O{text} v }{ ... }
. Try \CodeInline{\mycmd\par}
to see the difference.
Right!
Thank you for your help :)
The only thing I found annoying with this solution is that I cannot add a border and radius to the corners of the highlight. So the solution is a little bit ugly but it works.
Hi 👋 ,
I am trying to find a way to have a linebreak using
\NewTotalTCBox
in order to prevent line overflow.The goal is to have an inline code, but, that can be displayed on several lines if it too large.
Example:
As we can see,
\mintinline
works well (break line anywhere) when it's not inside a tcolorbox, but does not work anymore when it is inside aTotalTCBox
.