
가장 바깥쪽의 모든 괄호에 더 크게 또는/또는 굵게 만드는 등 텍스트 형식을 적용해야 하는 일부 텍스트 정보가 있습니다.
어떤 의미에서 나는 다음과 같은 텍스트를 처리하고 싶습니다.
^(...(...(...)...)...(..)..^)...^(..(....)..^)
^( 및 ^)에는 특별한 형식이 있습니다(기본적으로 내가 원하는 것은 텍스트와 같은 일부 수학 텍스트의 가장 바깥쪽 괄호를 눈에 띄게 만들어 읽기 쉽게 만드는 것입니다).
그것은 다음과 같이 보일 것입니다
(...(...(...)...)...(..)..)...(..(....)..)
이 작업을 쉽게 수행할 수 있는 아이디어가 있습니까? 텍스트가 복잡해지기 때문에 각 괄호에 \mathbf를 추가하고 싶지 않습니다.
(사실 저는 *( 바로 앞의 텍스트를 수정하고 서식을 적용하고 싶습니다(그 앞의 단어만).
그래서
썸텍스트(....)
SomeText 및 외부( )에 형식이 적용되지만 내부의 모든 내용은 그대로 유지됩니다.
가능한 한 텍스트를 어수선하게 만드는 것을 피하고 싶고 어떤 환경이 필요한 것 같아요?
답변1
다른 패키지, 특히 수학에 대한 의미를 결코 알지 못하기 때문에 나는 catcode를 망치지 않고 오히려 작은 파서를 제공할 것입니다. 작성자는 입력을 다음과 같이 삽입합니다.
\[\parser SomeWords (...(\alpha...(...)...)...(\beta)..)...(..(....)..);\]
\parser
원한다면 좀 더 의미론적인 의미를 부여할 수 있습니다 . 그러면 그 의미와 첫 번째 여는 괄호 사이의 모든 내용이 굵게 표시됩니다. 문자열에 수학이 포함되어 있지 않으면 \[..\]
.
LaTeX 커널 루프를 사용하여 첫 번째 여는 괄호와 마지막 세미콜론 사이의 내용을 문자별로 구문 분석합니다 @tfor
. 우리는 외부 루프와 내부 루프 사이의 균형을 유지하고 그에 따라 조판합니다. 결과는 다음과 같습니다.
MWE는 아래와 같습니다.
\documentclass{article}
\begin{document}
\makeatletter
\def\L{(}
\def\R{)}
%left counter
\newcounter{cnt}
\setcounter{cnt}{1}
%right counter
\newcounter{cntr}
\setcounter{cntr}{1}
%new counter balancing
\newcounter{bal}
\setcounter{bal}{0}
%define the parser
\def\parser#1(#2);{%
\textbf{#1 (}
\@tfor\next:=#2\do{%
\ifx\next\L \stepcounter{cnt}
\stepcounter{bal}
\ifnum\thebal=0 \textbf{\next}\else\normalfont\next\fi%
%
\else
\ifx\next\R \stepcounter{cntr}
\addtocounter{bal}{-1}
\ifnum\thebal=-1 \textbf{\next}\else\next\fi%
\else
\next
\fi
\fi
}%end forloop
\textbf{)}
}
\[\parser SomeWords (...(\alpha...(...)...)...(\beta)..)...(..(....)..);\]
\end{document}
답변2
아마도 \lgroup
/ \rgroup
바깥쪽 괄호에 대한 것일까요?
$$\lgroup a(b(c)) (d)\rgroup \lgroup e(fg) h\rgroup$$
\bye
매크로의 경우 괄호를 매크로 구분 기호로 사용하고 공백을 끝 구분 기호로 사용할 수 있습니다(예에서 행 변경은 공백, 즉 끝 구분 기호로 계산됩니다).
\def\someFormat#1{{\it #1\/}}
\def\thingamabob#1(#2) {{\someFormat{#1}\mathsurround0pt$\lgroup$#2$\rgroup$}}
\thingamabob SomeText(blah(foo)bar) \thingamabob (bar(baz)foo(blah))
\bye
\mathsurround0pt
는 >0으로 설정된 경우 수학 모드 변경 전/후에 추가된 공간이 없는지 확인하기 위한 것이며 주변 그룹은 이 명령 내에 해당 설정을 포함하기 위해 존재합니다 .
답변3
다음은 \important[<prefix>]{<stuff>}
해당 조판을 제공합니다.접두사(굵은 글씨체, 텍스트 모드) 및 주변을 강조 표시 형태로 <stuff>
사용 합니다. 또는 ("그룹"의 약어) 에서 제공하는 환경 스타일 접근 방식도 가능합니다 .\big(
\big)
grp
\documentclass{article}
\newcommand{\important}[2][]{\textbf{#1}\big(#2\big)}%
\newenvironment{grp}{\big(}{\big)}
\begin{document}
\[
\important[SomeText]{\ldots(\ldots(\ldots)\ldots)\ldots(\ldots)\ldots}\ldots\important{\ldots(\ldots)\ldots}
\]
\[
\textbf{SomeText}\begin{grp}\ldots(\ldots(\ldots)\ldots)\ldots(\ldots)\ldots\end{grp}\ldots\begin{grp}\ldots(\ldots)\ldots\end{grp}
\]
\end{document}
답변4
\outermost
위의 @wh1t3의 제안에 따라 첫 번째 여는 괄호 앞의 텍스트와 그 이후의 모든 가장 바깥쪽 괄호 쌍을 강조하는 명령을 정의하는 한 가지 방법이 있습니다 . 코드의 나머지 부분에서 괄호를 특별히 처리하지 않으려면 블록으로 격리해야 합니다.
강조 코드는 원하는 대로 변경할 수 있습니다. 특히 여기서는 이것이 텍스트 모드에서 사용될 것이라고 가정했기 때문에 를 사용 \textbf
하지만 \mathbf
(또는 아마도 괄호를 처리하는 가난한 사람의 대담한 명령) 이것을 수학 모드에서 사용하고 싶습니다.
이 접근 방식의 가장 큰 장점은 괄호가 포함된 텍스트에 추가 마크업이 필요하지 않다는 것입니다.
\documentclass{standalone} % for demonstration purposes
\makeatletter
\newcount\@nbegin % number of inner open parentheses in current block
\newcount\@nend % number of outer open parentheses in current block
\newcommand\@outermostopen{%
\@nbegin=0\@nend=0\relax%
\@beginisinner\@endisouter%
\@outermostem{(}}
\newcommand\@outermostclose{%
\@outermostem{)}%
\@beginisouter}
\newcommand\@inneropen{%
(%
\advance\@nbegin by 1\relax%
\@endisinner}
\newcommand\@innerclose{%
)%
\advance\@nend by 1
\ifnum\@nend=\@nbegin%
\@endisouter\fi%
}
\def\outermost#1({%
\catcode`(=\active
\catcode`)=\active
\@outermostem{#1}\@outermostopen%
}
{ % Commands that redefine parentheses themselves need to be defined
% in a context where () are active
\catcode`(=\active
\catcode`)=\active
\gdef\@beginisouter{%
\def({\@outermostopen}%
}
\gdef\@beginisinner{%
\def({\@inneropen}%
}
\gdef\@endisouter{%
\def){\@outermostclose}%
}
\gdef\@endisinner{%
\def){\@innerclose}%
}
}
\newcommand{\@outermostem}[1]{\textbf{\Large #1}}
% redefine for whatever emphasis method you want
\makeatother
\begin{document}
{\outermost Beginning(\dots(\dots)\dots)\dots(\dots)\dots(\dots(\dots(\dots)\dots(\dots)\dots)\dots)}
\end{document}
이는