Thay thế cho gói linh hồn?
Bối cảnh
Người ta có thể muốn đánh dấu một số văn bản hoặc đánh dấu nó. Điều này có thể được thực hiện với soulgói hoặc với ulemgói bằng thủ thuật , mặc dù nó không hoạt động tốt.
Vấn đề
Vấn đề tôi gặp phải với soul là nó hoạt động không tốt trên các bảng chú giải thuật ngữ, các lệnh mới hoặc các trích dẫn. Về cơ bản, bạn không thể lấy toàn bộ văn bản của mình và bao quanh nó bằng một dấu \hl{}như nó đã được thảo luận ở những nơi khác . Và giải pháp bằng \mbox{\gls{toto}}hoặc thậm chí chỉ {\gls{toto}}thực hiện thủ thuật.
Ví dụ, hãy xem ví dụ làm việc tối thiểu sau:
\documentclass{article}
\usepackage{soul}
\usepackage[acronym]{glossaries}
\usepackage{color}
\newacronym{co2}{CO$_2$}{carbon dioxide}
\newcommand{\etal}{\textit{et al.}}
\begin{document}
Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit.
Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\end{thebibliography}
\end{document}
mà biên dịch tốt trong khi:
[...]
\begin{document}
\hl{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit.
Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
[...]
đưa ra một loạt các thông báo lỗi, được sửa một phần bằng cách:
[...]
\begin{document}
Lorem ipsum \mbox{\gls{co2}} \hl{dolor by Toto \mbox{\etal{}} {\cite{latexcompanion}} sit amet, consectetur adipiscing elit.
Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \mbox{\gls{co2}}.}
[...]
mà không thành công nếu tôi bao gồm đầu tiên \mbox{\gls{co2}}trong \hl{}lệnh. Có lẽ là nó quá lâu?
Câu hỏi
- Chính xác là vấn đề giữa
soul's\hl{}lệnh và\cite{},\etal{}hoặc thuật ngữ mục? - Làm thế nào để giải quyết những vấn đề này? (các giải pháp được đề xuất chỉ hoạt động một phần)
- Có một giải pháp thay thế nào cho phép một cái gì đó giống như
\hl{}nhưng có thể bao quanh toàn bộ khối mã, có thể chứa các số liệu, văn bản, v.v. hay nói cách khác là có cách nào đơn giản để thay đổi màu nền của một phần chính xác không?
Điều tốt nhất tôi nghĩ ra là sử dụng hộp màu (xem thêm ở đây ), như thế này:
[...]
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
[...]
\begin{tcolorbox}[breakable,notitle,boxrule=0pt,colback=yellow,colframe=yellow]
Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit.
Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.
\end{tcolorbox}
[...]
Nhưng nó thay đổi định dạng văn bản ...
Trả lời
Bạn có thể sử dụng ulemgói để đạt được những gì bạn muốn, tôi đoán vậy. Ngoài ra còn có một thủ thuật để thực hiện soulcông việc.
CHỈNH SỬA: Liên quan đến câu hỏi thứ hai của bạn, liệu có cách nào đơn giản để thay đổi màu nền của một phần chính xác có thể chứa hình, văn bản, v.v. hay không, điều này không dễ dàng như vậy. Bạn có thể sử dụng các cách tiếp cận bao bọc nội dung của mình vào một môi trường khác, (như mdframedhoặc tcolorbox), nhưng điều này có thể ảnh hưởng đến định dạng của bạn và cũng có thể hạn chế một số lệnh / phần tử bên trong, đặc biệt là float. Tôi đã bao gồm một ví dụ dựa trên tcolorboxít nhất là phù hợp với nội dung đơn giản. Ngoài ra, tôi đã thêm một cách tiếp cận thay thế sử dụng afterpageđể thay đổi nền trang.
ulem
Xác định hllệnh của riêng bạn như thế này (cmp.https://tex.stackexchange.com/a/48549/223749):
\usepackage[normalem]{ulem}
\newcommand\hl{\bgroup\markoverwith
{\textcolor{yellow}{\rule[-.5ex]{.1pt}{2.5ex}}}\ULon}
Với điều này, MWE của bạn biên dịch tốt. (Hãy xemhttps://tex.stackexchange.com/a/254337/223749cho các vấn đề có thể xảy ra). Sử dụng soutlệnh từ ulembạn cũng có thể gạch ngang văn bản tương tự trong MWE mà không có lỗi.
MWE đầy đủ (MWE của bạn thiếu \makeglossarieslệnh):
\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand\hl{\bgroup\markoverwith
{\textcolor{yellow}{\rule[-.5ex]{.1pt}{2.5ex}}}\ULon}
\usepackage[acronym]{glossaries}
\usepackage{color}
\newacronym{co2}{CO$_2$}{carbon dioxide}
\newcommand{\etal}{\textit{et al.}}
\makeglossaries
\begin{document}
\hl{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
\sout{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\end{thebibliography}
\end{document}
Linh hồn
Nếu bạn muốn tiếp tục soul, cũng có một giải pháp cho các vấn đề của bạn bằng cách làm \soulregistertheo câu trả lời này (https://tex.stackexchange.com/a/139500/223749). Điều này cũng cung cấp một khả năng gạch ngang.
MWE đầy đủ:
\documentclass{article}
\usepackage{soul}
\soulregister\cite7
\soulregister\gls7
\soulregister\etal7
\usepackage[acronym]{glossaries}
\usepackage{color}
\newacronym{co2}{CO$_2$}{carbon dioxide}
\newcommand{\etal}{\textit{et al.}}
\makeglossaries
\begin{document}
\hl{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
\st{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\end{thebibliography}
\end{document}
tcolorbox
Với một số thủ thuật, bạn có thể tạo môi trường tô sáng tùy chỉnh với tcolorboxcông việc, thay đổi màu nền của một phần chính xác có thể chứa các hình, văn bản, v.v. Sử dụng tcolorboxmôi trường với tất cả các lề được đặt thành 0, và sau đó khôi phục \parindent, về cơ bản bạn sẽ có được văn bản vì nó sẽ ở bên ngoài hộp. Ngoài ra, bằng cách sử dụng floatgói và chỉ định Htùy chọn vị trí, bạn có thể bao gồm các môi trường float như tablehoặc figurebên trong - mặc dù chúng sẽ không thực sự nổi. Tôi đã sử dụng ulemtrong MWE để gạch ngang.
MWE sau đây chứa một hình và một bảng, cũng như ngắt trang.
\documentclass{article}
\usepackage{mwe}
\usepackage[acronym]{glossaries}
\usepackage{color}
\usepackage{float}
\usepackage[normalem]{ulem}
\newlength\defaultparindent
\AtBeginDocument{\setlength\defaultparindent{\parindent}}
\usepackage[breakable]{tcolorbox}
\newenvironment{highlighttcb}%
{\begin{tcolorbox}[colback=yellow,
colframe=white,
boxsep=0pt,
left=0pt,
right=0pt,
top=0pt,
bottom=0pt,
center,
valign=top,
before skip=0pt,
after skip=0pt,
width=\textwidth,
breakable,
boxrule=0pt,
frame empty,
sharp corners
]
\setlength{\parindent}{\defaultparindent}
}%
{\end{tcolorbox}}
\newacronym{co2}{CO$_2$}{carbon dioxide}
\newcommand{\etal}{\textit{et al.}}
\makeglossaries
\begin{document}
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\begin{highlighttcb}%
Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.
\sout{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
\begin{figure}[H]
\includegraphics[width=.4\textwidth]{example-image-a}\hfill
\includegraphics[width=.4\textwidth]{example-image-b}
\caption{This is a figure caption within tcolorbox.}
\end{figure}
\blindtext
\blindtext
\blindtext
\blindtext
\begin{table}[H]
\centering
\begin{tabular}{lcr}
a & b & c \\
a & b & c \\
a & b & c \\
\end{tabular}
\caption{This is a table caption within tcolorbox.}
\end{table}
\blindtext
\end{highlighttcb}
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\end{thebibliography}
\end{document}
pagecolor / afterpage
Cuối cùng, một cách tiếp cận thú vị là tô màu một phần nền trang bằng cách sử dụng colorvà afterpagecác gói (lấy từhttps://tex.stackexchange.com/a/237427/223749). Điều này có lợi thế là bạn không cần phải thay đổi nội dung của mình và định dạng sẽ không bị ảnh hưởng. Một nhược điểm có thể xảy ra (tùy thuộc vào mục đích của bạn) có thể là phần tô sáng sẽ bao gồm cả lề trái và lề phải. Ngoài ra, nếu bạn đã nổi bên trong môi trường làm nổi bật và chúng trôi ra khỏi môi trường đó, chúng sẽ không được đánh dấu.
MWE đầy đủ, bao gồm một hình và ngắt trang:
\documentclass{article}
\usepackage{mwe}
\usepackage[acronym]{glossaries}
\usepackage{color}
\usepackage[normalem]{ulem}
\usepackage{afterpage}
\makeatletter
% Macro \changepagecolor has the same syntax as \pagecolor or \color
% with an optional argument and a mandatory argument.
\newcommand*{\changepagecolor}{%
\@ifnextchar[\@changepagecolor@i\@changepagecolor@ii
}
% Case: \changepagecolor[...]{...}
\def\@changepagecolor@i[#1]#2{%
\@changepagecolor@do{[{#1}]{#2}}%
}
% Case: \changepagecolor{...}
\newcommand*{\@changepagecolor@ii}[1]{%
\@changepagecolor@do{{#1}}%
}
\newcommand*{\@changepagecolor@do}[1]{%
% Fill the remaining space with a colored rule
\begingroup
\offinterlineskip
\hbox to 0pt{%
\kern-\paperwidth
\vtop to 0pt{%
\color#1%
\hrule width 2\paperwidth height \paperheight
\vss
}%
\hss
}%
\endgroup
% Set page color for the next page
\afterpage{\pagecolor#1}%
}
\makeatother
\newenvironment{highlight}%
{\changepagecolor{yellow}}%
{\changepagecolor{white}}
\newacronym{co2}{CO$_2$}{carbon dioxide}
\newcommand{\etal}{\textit{et al.}}
\makeglossaries
\begin{document}
\blindtext
\blindtext
\blindtext
\blindtext
\begin{highlight}
Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.
\sout{Lorem ipsum \gls{co2} dolor by Toto \etal{}\cite{latexcompanion} sit amet, consectetur adipiscing elit. Etiam tortor sapien, rutrum vitae lacinia sit amet, mollis ac est. Aenean tortor orci \gls{co2}.}
\blindtext
\begin{figure}[!h]
\includegraphics[width=.4\textwidth]{example-image-a}\hfill
\includegraphics[width=.4\textwidth]{example-image-b}
\caption{This is a figure caption within the custom highlight environment}
\end{figure}
\end{highlight}
\blindtext
\begin{thebibliography}{9}
\bibitem{latexcompanion}
Michel Goossens, Frank Mittelbach, and Alexander Samarin.
\textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, Massachusetts, 1993.
\end{thebibliography}
\end{document}
Một cách khác là sử dụng gói "hiệu đính" và lệnh "\ hilite". Tuy nhiên, bạn phải sử dụng lệnh "\ protec" trước "\ gls" và đóng dấu ngoặc nhọn ngay sau "\ gls {}". Sau đó, sử dụng "\ hilite" một lần nữa để đánh dấu phần còn lại của văn bản.
\documentclass{article}
\usepackage{soulutf8} % Only necessary if there are accented characters inside the curly braces
\usepackage{proofread}
\usepackage[xindy]{glossaries}
\makeglossaries
\newglossaryentry{euismod}{
name={euismod},
description={euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo.}
}
\begin{document}
Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, \hilite{accumsan eleifend.
Nam dui ligula, fringilla a, \protect\gls{euismod}}\hilite{ sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo}. Nam lacus libero, pretium at.
\printglossary
\end{document}