I use the following code from this post to box-up selected inline text.
% Multiline Textbox
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}
\makeatletter
\newcommand{\gettikzxy}[3]{% from https://tex.stackexchange.com/a/58590/121799
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\global\edef#2{\the\pgf@x}%
\global\edef#3{\the\pgf@y}%
}
\makeatother
\newcommand{\BoxMe}[2][0.5pt]{%
\tikz[remember picture,overlay, baseline=(Begin.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (Begin) {\strut};}#2%
\tikz[remember picture,overlay, baseline=(End.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (End) {\strut};}%
\begin{tikzpicture}[overlay,remember picture]
\gettikzxy{($(Begin.north)-(current page.south west)$)}{\BeginxN}{\BeginyN}
\gettikzxy{($(End.north)-(current page.south west)$)}{\EndxN}{\EndyN}%\typeout{\BeginyN\space\EndyN}
\pgfmathtruncatemacro{\mytest}{\EndyN-\BeginyN}
\ifnum\mytest=0\relax% begin and and in the same line %\typeout{begin and end in the same line}
\draw[thick,-] ($(Begin.north)-(#1,0)$) -- ($(Begin.south)-(#1,0)$)
-- ($(End.south)+(#1,0)$) -- ($(End.north)+(#1,0)$) -- cycle;
\else% \typeout{end below begin}
\path (current page text area.north west) -- (current page text area.south west)
node(WestLine)[left]{};
\path (current page text area.north east) -- (current page text area.south east)
node(EastLine)[right]{};
\gettikzxy{($(End.north)-(current page.south west)$)}{\EndxN}{\EndyN}
\gettikzxy{($(Begin.south)-(current page.south west)$)}{\BeginxS}{\BeginyS}
\pgfmathtruncatemacro{\mytest}{\BeginyS-\EndyN+1pt}% \typeout{\mytest}
\ifnum\mytest<2\relax% \typeout{end in the next line after begin}%
\pgfmathtruncatemacro{\mytest}{\BeginxS-\EndxN}% \typeout{\mytest}
\ifnum\mytest>0\relax%
\draw[thick,-] (Begin.north -| EastLine) -- ($(Begin.north)-(#1,0)$) --
($(Begin.south)-(#1,0)$) -- (Begin.south -| EastLine);
\draw[thick,-] (End.south -| WestLine) -- ($(End.south)+(#1,0)$) --
($(End.north)+(#1,0)$) -- (End.north -| WestLine);
\else
\draw[thick,-] ($(Begin.north)-(#1,0)$) -- ($(Begin.south)-(#1,0)$) --
(Begin.south -| WestLine) -- (End.south -| WestLine)
-- ($(End.south)+(#1,0)$) -- ($(End.north)+(#1,0)$) -- (End.north -| EastLine)
-- (Begin.north -| EastLine) -- cycle;
\fi
\else
\draw[thick,-] ($(Begin.north)-(#1,0)$) -- ($(Begin.south)-(#1,0)$) --
(Begin.south -| WestLine) -- (End.south -| WestLine)
-- ($(End.south)+(#1,0)$) -- ($(End.north)+(#1,0)$) -- (End.north -| EastLine)
-- (Begin.north -| EastLine) -- cycle;
\fi
\fi
\end{tikzpicture}}
Unicode characters that have been boxed up do not display properly.
Sample Document:
% Created 2021-03-24 Wed 03:05
% Intended LaTeX compiler: xelatex
\documentclass[12pt,a4paper]{article}
%\documentclass[12pt,a4paper]{ctexart}
\usepackage{xeCJK}
\usepackage{zhnumber} % package for Chinese formatting of date time (use /zhtoday)
\usepackage[yyyymmdd]{datetime} % set date time to numeric
% For Generation of Citations and Bibliography
\usepackage[notes, isbn=false, backend=biber]{biblatex-chicago}
\bibliography{/Users/satibodhi/Creation/notes/bibliography/thesis}
% Dummy Text for Testing
\usepackage{lipsum}
\usepackage{zhlipsum}
% Multiline Textbox
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}
\makeatletter
\newcommand{\gettikzxy}[3]{% from https://tex.stackexchange.com/a/58590/121799
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\global\edef#2{\the\pgf@x}%
\global\edef#3{\the\pgf@y}%
}
\makeatother
\newcommand{\BoxMe}[2][0.5pt]{%
\tikz[remember picture,overlay, baseline=(Begin.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (Begin) {\strut};}#2%
\tikz[remember picture,overlay, baseline=(End.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (End) {\strut};}%
\begin{tikzpicture}[overlay,remember picture]
\gettikzxy{($(Begin.north)-(current page.south west)$)}{\BeginxN}{\BeginyN}
\gettikzxy{($(End.north)-(current page.south west)$)}{\EndxN}{\EndyN}%\typeout{\BeginyN\space\EndyN}
\pgfmathtruncatemacro{\mytest}{\EndyN-\BeginyN}
\ifnum\mytest=0\relax% begin and and in the same line %\typeout{begin and end in the same line}
\draw[thick,-] ($(Begin.north)-(#1,0)$) -- ($(Begin.south)-(#1,0)$)
-- ($(End.south)+(#1,0)$) -- ($(End.north)+(#1,0)$) -- cycle;
\else% \typeout{end below begin}
\path (current page text area.north west) -- (current page text area.south west)
node(WestLine)[left]{};
\path (current page text area.north east) -- (current page text area.south east)
node(EastLine)[right]{};
\gettikzxy{($(End.north)-(current page.south west)$)}{\EndxN}{\EndyN}
\gettikzxy{($(Begin.south)-(current page.south west)$)}{\BeginxS}{\BeginyS}
\pgfmathtruncatemacro{\mytest}{\BeginyS-\EndyN+1pt}% \typeout{\mytest}
\ifnum\mytest<2\relax% \typeout{end in the next line after begin}%
\pgfmathtruncatemacro{\mytest}{\BeginxS-\EndxN}% \typeout{\mytest}
\ifnum\mytest>0\relax%
\draw[thick,-] (Begin.north -| EastLine) -- ($(Begin.north)-(#1,0)$) --
($(Begin.south)-(#1,0)$) -- (Begin.south -| EastLine);
\draw[thick,-] (End.south -| WestLine) -- ($(End.south)+(#1,0)$) --
($(End.north)+(#1,0)$) -- (End.north -| WestLine);
\else
\draw[thick,-] ($(Begin.north)-(#1,0)$) -- ($(Begin.south)-(#1,0)$) --
(Begin.south -| WestLine) -- (End.south -| WestLine)
-- ($(End.south)+(#1,0)$) -- ($(End.north)+(#1,0)$) -- (End.north -| EastLine)
-- (Begin.north -| EastLine) -- cycle;
\fi
\else
\draw[thick,-] ($(Begin.north)-(#1,0)$) -- ($(Begin.south)-(#1,0)$) --
(Begin.south -| WestLine) -- (End.south -| WestLine)
-- ($(End.south)+(#1,0)$) -- ($(End.north)+(#1,0)$) -- (End.north -| EastLine)
-- (Begin.north -| EastLine) -- cycle;
\fi
\fi
\end{tikzpicture}}
% Set default indentation
\setlength\parindent{24pt}
% Set Paper Size, Page Layout (another variable is 'bindingoffset')
\usepackage[margin = 1.5in, paper = a4paper, inner = 2.5cm,
outer = 2.5cm, top = 3cm, bottom = 2.5cm]{geometry}
% Keep paragraph indentation while having a line break in between paragraphs.
\edef\restoreparindent{\parindent=\the\parindent\relax}
\usepackage{parskip}
\restoreparindent
% Indent first paragraph.
\usepackage{indentfirst}
\usepackage{titlesec}
\usepackage{titling}
\usepackage{fontspec} % packages for title and section-heading font setting.
\usepackage{newunicodechar} % custom fallback font for certain unicode characters.
\usepackage{tocloft} % adding the tocloft package for toc customization
\usepackage{titletoc} % custom toc indentation and label width.
% Set Header and Numbering Depth
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
% Set Font.
\setsansfont{Calibri}
\setmainfont{Times New Roman} % Set serifed font to Calibri. Originally set to 'Times New Roman', but it cannot display certain characters such as ①②③.
\setCJKmainfont{Songti TC}
\setCJKsansfont{Kaiti TC} % Set Chinese font. NOTE: Remember to append CJK before of the font class. CJK HAS to be there for the font to show.
\setCJKmonofont{PingFang TC}
% Set fallback fonts for ㊀ characters.
\newunicodechar{㊀}{{\ttfamily ㊀}}
\newunicodechar{㊁}{{\ttfamily ㊁}}
\newunicodechar{㊂}{{\ttfamily ㊂}}
\newunicodechar{㊃}{{\ttfamily ㊃}}
\newunicodechar{㊄}{{\ttfamily ㊄}}
\newunicodechar{㊅}{{\ttfamily ㊅}}
\newunicodechar{㊆}{{\ttfamily ㊆}}
\newunicodechar{㊇}{{\ttfamily ㊇}}
\newunicodechar{㊈}{{\ttfamily ㊈}}
\newunicodechar{㊉}{{\ttfamily ㊉}}
\newunicodechar{・}{{\ttfamily ・}}
\newCJKfontfamily\rarechar{HanaMinB}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
\newunicodechar{}{{\rarechar }}
% Set fallback fonts for ① characters.
\newunicodechar{①}{{\sffamily ①}}
\newunicodechar{②}{{\sffamily ②}}
\newunicodechar{③}{{\sffamily ③}}
\newunicodechar{④}{{\sffamily ④}}
\newunicodechar{⑤}{{\sffamily ⑤}}
\newunicodechar{⑥}{{\sffamily ⑥}}
\newunicodechar{⑦}{{\sffamily ⑦}}
\newunicodechar{⑧}{{\sffamily ⑧}}
\newunicodechar{⑨}{{\sffamily ⑨}}
\newunicodechar{⑩}{{\sffamily ⑩}}
\newunicodechar{✔}{{\sffamily ✔}}
\newunicodechar{Ⓐ}{{\sffamily Ⓐ}}
\newunicodechar{Ⓑ}{{\sffamily Ⓑ}}
\newunicodechar{Ⓒ}{{\sffamily Ⓒ}}
% WHEN \documentclass is set to {article},
% zhnum[style={Traditional,Financial}] doesn't work with the section counter,
% so we define our own counter and increase it every time in \thesection.
\newcounter{mysec}[section]
\renewcommand\thesection{%
\addtocounter{mysec}{1}%
\zhnum[style={Traditional,Financial}]{mysec}、} % 大標題序號:壹、貳、參、…
\renewcommand\thesubsection{\zhnum{subsection}、} % added a 、小標題序號:一、二、三、…
\renewcommand\thesubsubsection{(\zhnum{subsubsection})} % added parentheses
% (full-width, don't know if that's what you want) 副標題序號:(一)(二)(三)
\renewcommand\theparagraph{\arabic{paragraph}} % arabic numbering for paragraph
\renewcommand\thesubparagraph{} % no subparagraph numbering
% we have to adjust the spacing in the toc because the section label is longer than usual
% ottedcontents will be used instead. (see below)
% \addtolength\cftsecnumwidth{1em}
% \addtolength\cftsubsecindent{1em}
% \addtolength\cftsubsubsecindent{1em}
% Use dottedcontents from the titletoc package to adjust TOC indentation and label width.
\dottedcontents{section}[3em]{}{3.5em}{1pc} % larger label width (3.5em) to accommodate double digits.
\dottedcontents{subsection}[5.5em]{}{2.5em}{1pc}
\dottedcontents{subsubsection}[7.5em]{}{2.5em}{1pc}
\dottedcontents{paragraph}[9.5em]{}{2.5em}{1pc}
\dottedcontents{subparagraph}[11.5em]{}{2.5em}{1pc}
% Set formats for each heading level. 'sffamily' will point to the sans-serif font. In this case, 「楷體」.
% here we need to make sure the normal section counter is accessed
\titleformat{\section}{\LARGE\bfseries\sffamily\filcenter}
{\zhnum[style={Traditional,Financial}]{section}、}{.5em}{}
\titleformat{\subsection}{\Large\bfseries\sffamily}
\titleformat{\subsubsection}{\Large\bfseries\sffamily} % Set formats for each heading level. 'sffamily' will point to the sans-serif font. In this case, 「楷體」.
% The titlesec package is used over here to make use of \paragraph and \subparagraph as headings. Up to five levels of headings can be implemented this way.
% no extra version for numberless is necessary since no numbers are used anyways
% also you get newlines from omitting the [display] in \titleformat already
\titleformat{\paragraph}[block]
{\Large\bfseries\sffamily}{\theparagraph}{0.5em}{}
\titleformat{\subparagraph}[block]
{\large\mdseries\sffamily}{\thesubparagraph}{0.5em}{}
% we need the following so that they don't indent (second argument, 0em);
% you'll have to adjust the spacing though since this is not display style anymore:
\titlespacing{\paragraph}{0em}{3.25ex plus 1ex minus .2ex}{.75ex plus .1ex}
\titlespacing{\subparagraph}{0em}{3.25ex plus 1ex minus .2ex}{.75ex plus .1ex}
% Set title font.
\renewcommand{\maketitlehooka}{\sffamily}
% Set quotation font.
\usepackage{etoolbox}
\newCJKfontfamily\quotefont{Kaiti TC}
\AtBeginEnvironment{quote}{\quotefont\normalsize}
% Tweak default settings.
\renewcommand{\baselinestretch}{1.2} % Set line width.
\renewcommand{\contentsname}{\hfill\bfseries\Large 目\hspace{0.5cm} 錄\hfill} % Translate content page title to Chinese.
\renewcommand{\cftaftertoctitle}{\hfill} % Center contents title.
\renewcommand{\abstractname}{摘要} % Translate abstract title to Chinese.
\renewcommand{\tablename}{表} % Translate table to Chinese.
\renewcommand{\figurename}{圖} % Translate figure to Chinese.
% For text-boxes
\usepackage{mdframed}
\BeforeBeginEnvironment{minted}{\begin{mdframed}}
\AfterEndEnvironment{minted}{\end{mdframed}}
% For tables
\usepackage{float}
\restylefloat{table}
% [FIXME] ox-latex 的設計不良導致 hypersetup 必須在這裡插入
\usepackage{hyperref}
\hypersetup{
colorlinks=true, %把紅框框移掉改用字體顏色不同來顯示連結
linkcolor=[rgb]{0,0.37,0.53},
citecolor=[rgb]{0,0.47,0.68},
filecolor=[rgb]{0,0.37,0.53},
urlcolor=[rgb]{0,0.37,0.53},
pagebackref=true,
linktoc=all,}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage{amssymb}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\begin{document}
顏色(\BoxMe{容貌溫})【一九〇】(\BoxMe{變})也。以其中心與人(\BoxMe{交,悅也。中心悅})焉,遷于兄弟,戚也。(\BoxMe{戚而})信之,親(\BoxMe{也。親而篤之,})【一九一】愛\footnote{「愛」字,帛書字從「旡」從「夂」從「心」。}也。愛父,其繼愛人,仁也。· \
\end{document}
Errors:
Missing character: There is no 容 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 貌 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 溫 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 變 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 交 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no , in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 悅 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 也 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 。 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 中 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 心 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 悅 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 戚 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 而 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 也 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 。 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 親 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 而 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 篤 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no 之 in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
Missing character: There is no , in font Times New Roman/OT:script=latn;languag
e=dflt;mapping=tex-text;!
\(\)which is required syntax when drafting inline LaTeX code in org mode is causing the error. – Sati Mar 24 '21 at 03:34