For compiling my tex files into pdfs, a dos batch file named makepdf.bat is used like this:

set name=mybook

xelatex %name% -synctex=1
bibtex %name%

iconv -f utf-8 -t gbk %name%.bbl>%name%.bbl.bak
del %name%.bbl
ren %name%.bbl.bak %name%.bbl
replace_fs %name%.bbl ]//. ]//
fixbbl -cjk -sort=pinyin %name%
iconv -f gbk -t utf-8 %name%.bbl>%name%.bbl.bak
del %name%.bbl
ren %name%.bbl.bak %name%.bbl

iconv -f utf-8 -t gbk %name%.idx>%name%.idx.bak
del %name%.idx
ren %name%.idx.bak %name%.idx
cctmkind -s entropy.ist -C mixed %name%
iconv -f gbk -t utf-8 %name%.ind>%name%.ind.bak
del %name%.ind
ren %name%.ind.bak %name%.ind

xelatex %name% -synctex=1
xelatex %name% -synctex=1

del *.log *.aux *.bbl *.bbl.bak *.out *.thm *.toc *.log *.idx *.ind /s

start "D:\Tools\sumatrapdf\SumatraPDF" %name%.pdf -reuse-instance

In the above batch file,

  1. A few of bbl and idx files were generated by the first xelatex command.
  2. For some reason regarding files' encoding, they have to be converted from utf-8 encoding to gbk by using iconv.
  3. The resulting gbk encoded files are processed by special tools such as replace_fs, fixbbl, cctmkind and then converted back to utf-8 encoding.
  4. Run xelatex again and open the pdf file in SumtraPDF.

Due to knowing few about latexmk and perl, I have no idea on how to tranlate this bat file into a latexmkrc format. Can anybody help me with this trouble?

1 Answer 1


One way to do this is to create your own batch files to run instead of bibtex and makeindex. Let's call them mybibtex.bat and mymakeindex.bat. Then you configure latexmk to use these instead of the standard programs, e.g., by

$bibtex = 'mybibtex %R';
$makeindex = 'mymakeindex %R';

One implementation for these batch files is as follows: You start with mybibtex.bat having everything in the original batch file from the bibtex line to the rename command that gives the final bbl file. Similarly mymakeindex.bat contains the next block of commands, the ones that process the index. Then, in these files, you change %name% to %1 to correspond to the first argument of the batch file.

There are fancier solutions within latexmk, using a defined Perl subroutine: see the section "FORMAT OF COMMAND SPECIFICATIONS" in the latexmk documentation. But the invoked batch file solution is fine (and you can invoke the batch files yourself or from other batch files).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .