[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/LaTeX.pm (_convert) <@verb>:
From: |
Gavin D. Smith |
Subject: |
branch master updated: * tp/Texinfo/Convert/LaTeX.pm (_convert) <@verb>: Check \verb delimiter character is not used in contents, and change newlines to spaces. * tp/t/latex_tests.t (verb): New test. |
Date: |
Sun, 04 Dec 2022 09:27:34 -0500 |
This is an automated email from the git hooks/post-receive script.
gavin pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 83b3630e8c * tp/Texinfo/Convert/LaTeX.pm (_convert) <@verb>: Check
\verb delimiter character is not used in contents, and change newlines to
spaces. * tp/t/latex_tests.t (verb): New test.
83b3630e8c is described below
commit 83b3630e8cd6d766ddf5126c476070f284213761
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Dec 4 14:27:09 2022 +0000
* tp/Texinfo/Convert/LaTeX.pm (_convert) <@verb>:
Check \verb delimiter character is not used in contents,
and change newlines to spaces.
* tp/t/latex_tests.t (verb): New test.
---
ChangeLog | 7 +
tp/Texinfo/Convert/LaTeX.pm | 23 +-
tp/t/latex_tests.t | 10 +
.../formats_encodings/at_commands_in_refs.pl | 4 +-
tp/t/results/latex_tests/verb.pl | 231 +++++++++++++++++++++
tp/t/results/latex_tests/verb/res_latex/verb.tex | 52 +++++
6 files changed, 321 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fd3a0edefc..630574fd11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-12-04 Gavin Smith <gavinsmith0123@gmail.com>
+
+ * tp/Texinfo/Convert/LaTeX.pm (_convert) <@verb>:
+ Check \verb delimiter character is not used in contents,
+ and change newlines to spaces.
+ * tp/t/latex_tests.t (verb): New test.
+
2022-12-04 Gavin Smith <gavinsmith0123@gmail.com>
* doc/texinfo.tex (\verb): Turn off hyphenation as this can
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index a7ff25bb59..64e485bcc5 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -2614,15 +2614,30 @@ sub _convert($$)
# whether we are in another LaTeX macro would probably be a pain.
# It should be ok, though, as it is described as an error in the manual:
# It is not reliable to use @verb inside other Texinfo constructs
- $result .= "\\verb" .$element->{'info'}->{'delimiter'};
+ my $delim = $element->{'info'}->{'delimiter'};
+ my $contents = '';
+
push @{$self->{'formatting_context'}->[-1]->{'text_context'}}, 'ctx_raw';
if ($element->{'args'}) {
- $result .= _convert($self, $element->{'args'}->[0]);
+ $contents = _convert($self, $element->{'args'}->[0]);
+ $contents =~ s/\n/ /;
}
my $old_context = pop
@{$self->{'formatting_context'}->[-1]->{'text_context'}};
die if ($old_context ne 'ctx_raw');
- $result .= $element->{'info'}->{'delimiter'};
- return $result;
+
+ # Check delimiter is not in contents. If it is, try other characters.
+ for my $char ($delim, '|', '!', ':', '@') {
+ if (index($contents, $char) == -1) {
+ $result .= "\\verb$char$contents$char";
+ return $result;
+ }
+ }
+ $self->line_warn($self,
+ sprintf(__("\\verb delimiter `%s' (for LaTeX) used in text `%s'"),
+ $delim, $contents),
+ $element->{'source_info'});
+ return "\\verb$delim$delim";
+
} elsif ($cmdname eq 'image') {
if (defined($element->{'args'}->[0])
and $element->{'args'}->[0]->{'contents'}
diff --git a/tp/t/latex_tests.t b/tp/t/latex_tests.t
index 24d268876b..949b315be4 100644
--- a/tp/t/latex_tests.t
+++ b/tp/t/latex_tests.t
@@ -561,6 +561,16 @@ New para
@end example
@end cartouche
'],
+['verb',
+'@verb{!a!}
+
+@verb{!a!a!}
+
+@verb{!a
+b!}
+
+@verb{%a%|!:@b%}
+'],
['nested_itemize',
'@itemize
@item First level item
diff --git a/tp/t/results/formats_encodings/at_commands_in_refs.pl
b/tp/t/results/formats_encodings/at_commands_in_refs.pl
index 526f770709..7e4e36e7bd 100644
--- a/tp/t/results/formats_encodings/at_commands_in_refs.pl
+++ b/tp/t/results/formats_encodings/at_commands_in_refs.pl
@@ -18598,7 +18598,7 @@
$result_converted{'latex_text'}->{'at_commands_in_refs'} = '\\begin{document}
\\chapter{{\\includegraphics{f--ile1}
\\includegraphics[width=aze,height=az]{f--ile}}}
\\label{anchor:f_002d_002dile1-f_002d_002dile}%
-\\chapter{{\\verb. @ {} . .}}
+\\chapter{{\\verb| @ {} . |}}
\\label{anchor:-_0040-_007b_007d-_002e-}%
\\chapter{{\\Texinfocommandstyletextcite{cite asis} \\hbox{in @w \\textbf{b}}
\\textnormal{in r} \\textsc{sc} \\textbf{str} \\texttt{t}
\\Texinfocommandstyletextvar{var} \\textsl{dfn} \\textit{i}}}
@@ -18660,7 +18660,7 @@
$result_converted{'latex_text'}->{'at_commands_in_refs'} = '\\begin{document}
\\hyperref[anchor:f_002d_002dile1-f_002d_002dile]{\\chaptername~\\ref*{anchor:f_002d_002dile1-f_002d_002dile}
[\\includegraphics{f--ile1} \\includegraphics[width=aze,height=az]{f--ile}],
page~\\pageref*{anchor:f_002d_002dile1-f_002d_002dile}}
-\\hyperref[anchor:-_0040-_007b_007d-_002e-]{\\chaptername~\\ref*{anchor:-_0040-_007b_007d-_002e-}
[\\verb. @ {} . .], page~\\pageref*{anchor:-_0040-_007b_007d-_002e-}}
+\\hyperref[anchor:-_0040-_007b_007d-_002e-]{\\chaptername~\\ref*{anchor:-_0040-_007b_007d-_002e-}
[\\verb| @ {} . |], page~\\pageref*{anchor:-_0040-_007b_007d-_002e-}}
\\hyperref[anchor:cite-asis-in-_0040w-b-in-r-SC-str-t-var-dfn-i]{\\chaptername~\\ref*{anchor:cite-asis-in-_0040w-b-in-r-SC-str-t-var-dfn-i}
[\\Texinfocommandstyletextcite{cite asis} \\hbox{in @w \\textbf{b}}
\\textnormal{in r} \\textsc{sc} \\textbf{str} \\texttt{t}
\\Texinfocommandstyletextvar{var} \\textsl{dfn} \\textit{i}],
page~\\pageref*{anchor:cite-asis-in-_0040w-b-in-r-SC-str-t-var-dfn-i}}
diff --git a/tp/t/results/latex_tests/verb.pl b/tp/t/results/latex_tests/verb.pl
new file mode 100644
index 0000000000..3f376ba2d1
--- /dev/null
+++ b/tp/t/results/latex_tests/verb.pl
@@ -0,0 +1,231 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors
+ %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'verb'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'contents' => [],
+ 'type' => 'preamble_before_content'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'a',
+ 'type' => 'raw'
+ }
+ ],
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'verb',
+ 'info' => {
+ 'delimiter' => '!'
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 1,
+ 'macro' => ''
+ }
+ },
+ {
+ 'text' => '
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'a!a',
+ 'type' => 'raw'
+ }
+ ],
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'verb',
+ 'info' => {
+ 'delimiter' => '!'
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 3,
+ 'macro' => ''
+ }
+ },
+ {
+ 'text' => '
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'a
+',
+ 'type' => 'raw'
+ },
+ {
+ 'text' => 'b',
+ 'type' => 'raw'
+ }
+ ],
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'verb',
+ 'info' => {
+ 'delimiter' => '!'
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => ''
+ }
+ },
+ {
+ 'text' => '
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'a%|!:@b',
+ 'type' => 'raw'
+ }
+ ],
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'verb',
+ 'info' => {
+ 'delimiter' => '%'
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 8,
+ 'macro' => ''
+ }
+ },
+ {
+ 'text' => '
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ }
+ ],
+ 'type' => 'before_node_section'
+ }
+ ],
+ 'type' => 'document_root'
+};
+
+$result_texis{'verb'} = '@verb{!a!}
+
+@verb{!a!a!}
+
+@verb{!a
+b!}
+
+@verb{%a%|!:@b%}
+';
+
+
+$result_texts{'verb'} = 'a
+
+a!a
+
+a
+b
+
+a%|!:@b
+';
+
+$result_errors{'verb'} = [];
+
+
+$result_floats{'verb'} = {};
+
+
+
+$result_converted{'latex_text'}->{'verb'} = '\\begin{document}
+\\verb!a!
+
+\\verb|a!a|
+
+\\verb!a b!
+
+\\verb%%
+';
+
+$result_converted_errors{'latex_text'}->{'verb'} = [
+ {
+ 'error_line' => 'warning: \\verb delimiter `%\' (for LaTeX) used in text
`a%|!:@b\'
+',
+ 'file_name' => '',
+ 'line_nr' => 8,
+ 'macro' => '',
+ 'text' => '\\verb delimiter `%\' (for LaTeX) used in text `a%|!:@b\'',
+ 'type' => 'warning'
+ }
+];
+
+
+$result_converted_errors{'file_latex'}->{'verb'} = [
+ {
+ 'error_line' => 'warning: \\verb delimiter `%\' (for LaTeX) used in text
`a%|!:@b\'
+',
+ 'file_name' => '',
+ 'line_nr' => 8,
+ 'macro' => '',
+ 'text' => '\\verb delimiter `%\' (for LaTeX) used in text `a%|!:@b\'',
+ 'type' => 'warning'
+ }
+];
+
+
+1;
diff --git a/tp/t/results/latex_tests/verb/res_latex/verb.tex
b/tp/t/results/latex_tests/verb/res_latex/verb.tex
new file mode 100644
index 0000000000..048961c7ca
--- /dev/null
+++ b/tp/t/results/latex_tests/verb/res_latex/verb.tex
@@ -0,0 +1,52 @@
+\documentclass{book}
+\usepackage{amsfonts}
+\usepackage{amsmath}
+\usepackage[gen]{eurosym}
+\usepackage{textcomp}
+\usepackage{graphicx}
+\usepackage{etoolbox}
+\usepackage{titleps}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{float}
+% use hidelinks to remove boxes around links to be similar to Texinfo TeX
+\usepackage[hidelinks]{hyperref}
+
+\makeatletter
+\newcommand{\Texinfosettitle}{No Title}%
+
+% redefine the \mainmatter command such that it does not clear page
+% as if in double page
+\renewcommand\mainmatter{\clearpage\@mainmattertrue\pagenumbering{arabic}}
+\newenvironment{Texinfopreformatted}{%
+ \par\GNUTobeylines\obeyspaces\frenchspacing\parskip=\z@\parindent=\z@}{}
+{\catcode`\^^M=13 \gdef\GNUTobeylines{\catcode`\^^M=13 \def^^M{\null\par}}}
+\newenvironment{Texinfoindented}{\begin{list}{}{}\item\relax}{\end{list}}
+
+% used for substitutions in commands
+\newcommand{\Texinfoplaceholder}[1]{}
+
+\newpagestyle{single}{\sethead[\chaptername{} \thechapter{}
\chaptertitle{}][][\thepage]
+ {\chaptername{} \thechapter{}
\chaptertitle{}}{}{\thepage}}
+
+% allow line breaking at underscore
+\let\Texinfounderscore\_
+\renewcommand{\_}{\Texinfounderscore\discretionary{}{}{}}
+\renewcommand{\includegraphics}[1]{\fbox{FIG \detokenize{#1}}}
+
+\makeatother
+% set default for @setchapternewpage
+\makeatletter
+\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{\Texinfoplaceholder{setchapternewpage
placeholder}\clearpage}{}{}
+\makeatother
+\pagestyle{single}%
+
+\begin{document}
+\verb!a!
+
+\verb|a!a|
+
+\verb!a b!
+
+\verb%%
+\end{document}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/LaTeX.pm (_convert) <@verb>: Check \verb delimiter character is not used in contents, and change newlines to spaces. * tp/t/latex_tests.t (verb): New test.,
Gavin D. Smith <=