auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cannot expand string in command on 13.0.3


From: Tak Kunihiro
Subject: Re: Cannot expand string in command on 13.0.3
Date: Wed, 13 Jan 2021 16:59:03 +0900

>> (defun sesame-TeX-jobname ()
>>   "Return option `-jobname' or empty string."
>>   (TeX-active-master-with-quotes nil t)
>>   ;; " -jobname=LaTexMkJob"
>>   "")
>> 
>> (defun sesame-TeX-outdir (&optional looptex-p)
>>   "Return option `-outdir' or empty string."
>>   (TeX-active-master-with-quotes nil t)
>>   " -outdir=~/deleteme.d")
>> 
>> Messages I expect and I got then are shown below.
>> 
>> expect:  Running `make' on `report' with ``latexmk -interaction=nonstopmode 
>> -file-line-error report.tex''
>> I got:   Running `make' on `report' with ``latexmk 
>> -interaction=nonstopmode%(outdir) -file-line-error report.tex''
>> 
>> It seems that when TeX-active-master-with-quotes is called
>> from TeX-command-expand, something happens.
> 
> Yes, indeed.  `TeX-active-master-with-quotes' expects that its value is
> actually inserted into the expansion and thusly it increase
> `TeX-expand-pos' accordingly.  Therefore, matching continues further
> behind so that %(outdir) doesn't get expanded.  AFAICS, the docstring of
> `TeX-active-master-with-quotes' is pretty clear about that.
> 
> In your example config, you call `TeX-active-master-with-quotes' for no
> reason.  Why do you do that?

Real sesame-TeX-jobname and sesame-TeX-outdir are shown below.

It seems I have to write sesame-TeX-target-region-p,
as shown below, without calling (TeX-active-master-with-quotes nil t).

Please give me hint.

TIA


(defun sesame-TeX-jobname ()
  "Return option `-jobname' according to target file (where command will be) to 
be used in `TeX-expand-list'."
  ;; | TeX-target            | return              |
  ;; |-----------------------+---------------------|
  ;; | _region_intro_figure0 | -jobname="figure3_" |
  ;; | manuscript or report  | <nothing>           |
  (if (sesame-TeX-target-region-p)
      ;; (format "\"%s_\"" (file-name-sans-extension 
(TeX-current-file-name-master-relative)))
      (format " -jobname=%s_" (shell-quote-argument (file-name-base 
buffer-file-name))) ; figure3_
    "")) ; there is no point to give something when option is empty

(defun sesame-TeX-outdir (&optional looptex-p)
  "Return option `-outdir' according to target file.
The returned values are used in `TeX-expand-list'.  With
LOOPTEX-P non-nil, it is deflected to `sesame-junk-dir'.  Three
possible outdirs are <master-dir> where master-file is,
<master-dir>/<subdir> where subfile is, and <junk-dir>."
  ;; | case | looptex-p | subcompile-p | return                |
  ;; |------+-----------+--------------+-----------------------|
  ;; |    1 | f         | f            | <master-dir>          |
  ;; |    2 | f         | t            | <master-dir>/<subdir> |
  ;; |    3 | t         | f            | <junk-dir>            |
  ;; |    4 | t         | t            | <junk-dir>            |
  (let* ((subcompile-p (sesame-TeX-target-region-p))
         (subdir
          (or (file-name-directory (TeX-current-file-name-master-relative)) ""))
         (outdir (if looptex-p
                     (directory-file-name (sesame-junk-dir))
                   (if subcompile-p
                       (directory-file-name subdir)
                     ""))))
    (if (string= outdir "")
        "" ; there is no point to give something when option is empty
      (format " -outdir=%s" (shell-quote-argument outdir)))))

(defun sesame-TeX-target-region-p ()
  "Return if target file (where command will be) is set on region or master.
This only works when called in `TeX-expand-list'.  See also
`sesame-TeX-jobname'."
  ;; | TeX-target            | then |
  ;; |-----------------------+------|
  ;; | _region_intro_figure0 | t    |
  ;; | manuscript or report  | nil  |
  (let ((TeX-target (if (fboundp 'TeX-active-master-with-quotes)
                        (TeX-active-master-with-quotes nil t) ; AUCTeX 13.0.3
                      (funcall file nil t)))) ; AUCTeX 12.3.1
    ;; (message "TeX-target is |%s|." TeX-target)
    ;; See `TeX-expand-list-builtin' for usage of `file' or 
`TeX-active-master-with-quotes'.
    ;; `file' returns strings wrapped by double quote on w32
    (or (string= TeX-target (TeX-region-file nil t)) ; _region_intro_figure3
        (string= TeX-target (format "\"%s\"" (TeX-region-file nil t)))))) ; 
"_region_intro_figure3"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]