1

I've a problem using TexStudio. I've defined a user command to copy the pdf in another directory every time it is re-compiled. I've done both on Windows 10 and Ubuntu 16.04, using respectively:

cmd /C copy %.pdf D:\folder
bash -c "cp -t ~/folder %.pdf"

If i try the command clicking on "Tool > user > Copy PDF" they correctly work.

So i tried to insert this command inside the Meta Command "Build & View" using | txs:///copypdf, but the command is not executed clicking on Build&View. The same problem on Windows and linux...

Am I doing something wrong or what? Thank you

UPDATE: seems that changing Meta commands is not effective enter image description here

The .bat contains:

D:
copy D:\babla\blabla\File.pdf D:\Dropbox\blabla\blabla\

TeXstudio 2.12.6

  • I tried also other command and is the same: launching the command from Tool works, inserting in Meta Command and running Build & View not... – Polonio Mar 7 '18 at 19:02
  • Meta commands seems to not react from changing definitions – Polonio Mar 7 '18 at 19:05
  • it works for me (windows 10). what's your TXS version? Does it work if you use txs:///user0 instead of txs:///copypdf (or whichever slot your cmd is on)? – Troy Mar 7 '18 at 19:36
  • As a workaround -- if you can't find what's wrong (it should...), you can make use of event triggers (specifically the ?after-command-run) and throw your cmds into a user macro. It should achieve the same effect. – Troy Mar 7 '18 at 19:49
  • 1
    I might be wrong and this is not quite what was asked, but this looks very much the task of a symlink... – gusbrs Mar 7 '18 at 22:04
1

You might try a User macro implementation of whatever you're trying to achieve, which should hopefully work.

ps. I should note that the following macro was written with Windows 10 OS in mind -- do make the appropriate changes for other OS yourself. I'll describe the outputs of each line of the script so hopefully it is easy for you to work out what you need to change.

I am also assuming you are copying your .pdf file from your working directory (i.e., where your master/root .tex file is) to a folder in D drive called folder (i.e., location D:\folder)


Under Macros -> Edit Macros, click Add on the bottom left corner of the popup window, and paste the following:

%SCRIPT
full_dir = editor.fileName().replace(/\//,"\\")
file_name = full_dir.split(".tex")[0]
system('cmd /C "copy '+file_name+'.pdf D:\\folder"')

and give it an event trigger, ?after-command-run, as shown in the pic below:

enter image description here

Click Ok, then now, whenever a command run has ended (e.g. at the end of a Build and View call), this script will automatically be activated, and it should copy to the designated folder.


A short explanation

  • Line 1: editor.filename() returns a string containing the full directory of the master .tex file (which should also be where the .pdf is generated). For example, it could be something like

    C:/Users/.../main.tex
    

    (where the ... is just the relevant paths leading to your main.tex.)

    • I then changed all the / (forward slash) in the directory string to a \ (backslash) via regex replacement, because Windows uses backslashes. I'm guessing this isn't the case for other OS, so you can leave the .replace(...) statement out in that case.
  • Line 2: Note also the result of editor.filename() leaves a .tex extension at the end. So I removed it in this line.

  • Line 3: Here, the system command passes its argument to the command line, and we need to invoke shell explicitly and is OS-dependent: (Read the TXS user manual, under Section 1.3.2, Shell functionality, for more info):

    For Mac OS / Linux:

    sh -c "<cmds>"
    

    For Windows:

    cmd /C "<cmds>"
    

    Lastly, note the D:\\folder part of Line 3. Just change that to whatever directory/folder you wish to copy the .pdf to. Make sure that folder actually exists.


If it is actually successful in running, you should see a message 1 file(s) copied appear in the Messages box at the bottom.

| improve this answer | |
  • Thank you very much, it works perfectly!! Just fix the missing "g" in line 1 (there was in the screen). I really appreciated your clear explaination, it is useful for me. I'm still curious to know why Meta doesn't wok.... but the result is the same – Polonio Mar 8 '18 at 0:05
  • @Polonio24 Oops, I decided while writing the answer that a global ('g') scope was not required. It's not essential to the answer regardless. From what I can see from your pic, I don't see a reason why it should not work. In other circumstances, I might suggest a resetting of TXS settings, but since the macro works, I would say just stick with this. (It's a cleaner way of achieving what you want anyway, imo.) – Troy Mar 8 '18 at 0:08
  • 1
    Really without g the script didn't work for me... hower is strange that the Meta didn't work on linux too.... That said, excellent solution, thanks! – Polonio Mar 8 '18 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.