Skip to content

Commit

Permalink
Addresses #10. Left-over for #10. There were still multiple runs of t…
Browse files Browse the repository at this point in the history
…exfrag-region for derived major modes.
  • Loading branch information
TobiasZawada committed May 1, 2019
1 parent 8124f2a commit 00a9d74
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
66 changes: 33 additions & 33 deletions test/README_TEST.org
Original file line number Diff line number Diff line change
Expand Up @@ -140,39 +140,39 @@ b(x) = (x_{i+d}-x_i)\cdot [x_i,\ldots,x_{i+d}]_y (y-x)^d_+

Second html document for testing with eww:
#+BEGIN_SRC html :tangle /tmp/test1.html :results silent
<!DOCTYPE html>
<head>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'>
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<title>Second texfrag html test for eww</title>
</head>
<body>
<h1>Second texfrag html test for eww</h1>
<p>
MathJax test.
<ul>
<li>Testing parenthesis fragments: The theorem of Pythagoras: \(\def\di{\operatorname{d}}\def\ph{\varphi}\def\I{\operatorname{i}}Z=\sqrt{X^2 + Y^2}\).</li>
<li>Testing dollar fragments: Einstein's formula of the photo-voltaic process: $E\;=\;h\cdot f$</li>
<li>Testing bracket fragments: B-spline basis function
\[
b(\xi) = (x_{i+d}-x_i)\cdot [x_i,\ldots,x_{i+d}]_y (y-\xi)^d_+
\]
</li>
<li>Testing LaTeX environments: Cauchy's integral formula
\begin{align*}
\frac1{2\pi\I}\oint_C \frac{f(Z)}{Z-z_0}\di Z &= \lim_{r\downarrow0} \frac1{2\pi\I}\int_{\ph=0}^{2\pi} \frac{f(z_0+r\exp(\I\ph))}{r\exp(\I\ph)}r\exp(\I\ph) \I\di \ph\\
&= f(z)
\end{align*}
</li>
</ul>
</p>
</body>
<!DOCTYPE html>
<head>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'>
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<title>Second texfrag html test for eww</title>
</head>
<body>
<h1>Second texfrag html test for eww</h1>
<p>
MathJax test.
<ul>
<li>Testing parenthesis fragments: The theorem of Pythagoras: \(\def\di{\operatorname{d}}\def\ph{\varphi}\def\I{\operatorname{i}}Z=\sqrt{X^2 + Y^2}\).</li>
<li>Testing dollar fragments: Einstein's formula of the photo-voltaic process: $E\;=\;h\cdot f$</li>
<li>Testing bracket fragments: B-spline basis function
\[
b(\xi) = (x_{i+d}-x_i)\cdot [x_i,\ldots,x_{i+d}]_y (y-\xi)^d_+
\]
</li>
<li>Testing LaTeX environments: Cauchy's integral formula
\begin{align*}
\frac1{2\pi\I}\oint_C \frac{f(Z)}{Z-z_0}\di Z &= \lim_{r\downarrow0} \frac1{2\pi\I}\int_{\ph=0}^{2\pi} \frac{f(z_0+r\exp(\I\ph))}{r\exp(\I\ph)}r\exp(\I\ph) \I\di \ph\\
&= f(z)
\end{align*}
</li>
</ul>
</p>
</body>
#+END_SRC


Expand Down
26 changes: 19 additions & 7 deletions texfrag.el
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ This can be a file name or a sexp that generates the file name."
(list :tag "Generator function" :inline t (const :generator) (function identity)))))
"Customization type for `texfrag-frag-alist'.")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar-local texfrag-preview-buffer-at-start-done nil
"Set to t if `texfrag-region' is run in function `texfrag-mode'.
Protection against repeated execution of `texfrag-region'
through function `texfrag-mode' with non-nil `texfrag-preview-buffer-at-start'
in the case of derived modes.")

(define-widget 'texfrag-regexp 'string
"A regular expression."
:match 'texfrag-widget-regexp-match
Expand Down Expand Up @@ -442,7 +450,7 @@ for further details about the argument and the return value."
(cMatches (texfrag-combine-match-data bStr bMatches eStr eMatches))
)
(unless eOuter
(user-error "LaTeX fragment beginning at %s with %s not closed." bOuter bStr)) ;; Changed %d for bOuter to %s to handle case bOuter==nil.
(user-error "LaTeX fragment beginning at %s with %s in buffer %s not closed" bOuter bStr (current-buffer))) ;; Changed %d for bOuter to %s to handle case bOuter==nil.
(set-match-data cMatches)
(list bOuter eOuter
(concat (replace-match (nth 2 matchList) nil nil cStr)
Expand Down Expand Up @@ -470,7 +478,7 @@ for further details about the argument and the return value."
(cStr (concat bStr eStr))
)
(unless bOuter
(user-error "LaTeX fragment ending at %d with %s has no start string." bOuter eStr))
(user-error "LaTeX fragment ending at %d with %s has no start string" bOuter eStr))
(set-match-data cMatches)
(list bOuter eOuter
(concat (replace-match (nth 2 matchList) nil nil cStr)
Expand Down Expand Up @@ -662,7 +670,7 @@ This variable is the link back from the LaTeX-buffer to the source buffer.")
(declare (debug body))
`(progn
(unless (buffer-live-p texfrag-source-buffer)
(user-error "TeXfrag source buffer %S not ready in LaTeX target buffer %S." texfrag-source-buffer (current-buffer)))
(user-error "TeXfrag source buffer %S not ready in LaTeX target buffer %S" texfrag-source-buffer (current-buffer)))
(with-current-buffer texfrag-source-buffer
,@body)))

Expand All @@ -671,7 +679,7 @@ This variable is the link back from the LaTeX-buffer to the source buffer.")
(declare (debug body))
`(progn
(unless (buffer-live-p texfrag-tex-buffer)
(user-error "TeXfrag LaTeX buffer %S not ready in LaTeX target buffer %S." texfrag-tex-buffer (current-buffer)))
(user-error "TeXfrag LaTeX buffer %S not ready in LaTeX target buffer %S" texfrag-tex-buffer (current-buffer)))
(with-current-buffer texfrag-tex-buffer
,@body)))

Expand Down Expand Up @@ -764,7 +772,7 @@ or the string itself."

(defun texfrag-generator-place-preview (ov img _box &optional _counters _tempdir &rest _place-opts)
"Call me like `preview-gs-place'.
Return OV after setting 'preview-image to a cons (img . img)
Return OV after setting 'preview-image to a cons (IMG . IMG)
assuming that img is already an image."
(when (stringp img)
(setq img (expand-file-name img))
Expand Down Expand Up @@ -999,11 +1007,15 @@ Example:
(define-key texfrag-mode-map texfrag-prefix texfrag-submap)
(LaTeX-preview-setup)
(preview-mode-setup)
(when texfrag-preview-buffer-at-start
(preview-buffer))
(when (and texfrag-preview-buffer-at-start
;; Protect against multiple activation in derived major modes:
(null texfrag-preview-buffer-at-start-done))
(preview-buffer)
(setq texfrag-preview-buffer-at-start-done t))
(add-hook 'kill-buffer-hook #'texfrag-cleanup nil t)
(add-hook 'change-major-mode-hook #'texfrag-cleanup nil t))
(texfrag-cleanup)
(setq texfrag-preview-buffer-at-start-done nil)
(remove-hook 'kill-buffer-hook #'texfrag-cleanup t)
(remove-hook 'change-major-mode-hook #'texfrag-cleanup t)
(preview-clearout-document)))
Expand Down

0 comments on commit 00a9d74

Please sign in to comment.