# Difference between *.tex and *.txt Files

Is there any difference between the two file-formats? Do I see all the data, when I open a .tex file using a Standard Text-Editor in Windows? Do .tex files have some kind of meta-data or disguised data I would not see?

My issue is like this. I have received a .tex file I would like to process. Would it be the same if I:

1. Process it directly
2. Open it using standard Windows Text-Editor, copy-paste the Content to a newly created .tex file (using e.g. TexnicCenter) and then process this resulting .tex file.

I would like to avoid any kind of malware or stuff like this. When I use the second approach I actually see the content since I copy-paste only the visible data.

• A .tex file is just text. – egreg Sep 15 '14 at 16:12
• Barring any differences in file encodings (UTF-8 or others), yes, the result would be the same. – Paul Gessler Sep 15 '14 at 16:12
• tex files are plain text (and can have any extension or no extension at all) – David Carlisle Sep 15 '14 at 16:12
• I suspect two problems when copy-paste of simple text from one application to another is completed. First: long lines can be broken. Second: encoding can be changed because of some unwanted intelligence of used applications. Both types of changes can cause different processing in TeX. Maybe, copy-paste can do 1:1 but it cannot. It depens on operating system and on used applications. – wipet Sep 15 '14 at 20:15
• For what it's worth, opening any file in a text editor will always show you all the content of the file. For some files (like .exe files) part of that content will be invisible/unprintable characters, and the rest will look like gibberish, but the point is, a text editor will attempt to faithfully display every single byte in the file. Text editors don't have any concept of macros or formatting commands or any other sort of hidden data. – David Z Sep 16 '14 at 7:24

File extensions are mainly a naming convention. Source code in almost all programming languages is plain text, and there is no technical difference between a file named .txt or .tex or .asdasdasd or whatever.

• how about filename.exe? – kiss my armpit Sep 15 '14 at 16:19
• @Ohmyghost In terms of file content it makes no odds :-) Note for example that .com is used by some programs to mean something very different from the classic DOS executable of the same extension. – Joseph Wright Sep 15 '14 at 16:20
• @Ohmyghost TeX would be quite happy with that file name (whether a windows editor opens it by default is a different question) – David Carlisle Sep 15 '14 at 16:20
• @JosephWright and \ampersand David: OK Thanks. – kiss my armpit Sep 15 '14 at 16:22
• @Ohmyghost .exe in windows generally tells the operating system, that the file is executable and therefore has the right format to be put into the processor. Other file extensions are registered to be opened with certain editors like notepad or Word or whatever. But because of the stupidity of notepad you can be shure that there is no meta information in a file when you can open it in notepad without any problems and there are no awkward symbols. – Arne Sep 15 '14 at 19:01

As mentioned in the comments, .tex files are just plain-text files, so they do not have "hidden metadata".

If you inspect it with any text editor as Notepad, TeXnicCenter etc... you will see the contents byte per byte (encoding issues apart, which are off-topic it would seem).

If your concern is how safe it is to run latex (or variants) on the file, the answer is simple. It is pretty safe, the worst it can do is be stuck in a loop and produce some garbage in the form of easy-to-delete temporary .aux files. Things change if you compile it using the -shell-escape argument: this would allow the .tex file to execute external programs and this could be potentially harmful. You can explicitly disable this behaviour by running the latex command with the -no-shell-escape argument.

There are packages that make legitimate use of this feature (minted comes to mind). To be sure nothing nasty is going to happen you need to inspect the contents of the .tex file.

But: Absolutely no harm can be caused by inspecting the file with a text editor.

As mentioned before, even plain-text files can be harmful in Windows if assigned extensions that instruct the operating system to interpret them as programs (examples are .bat files or .vbs). To avoid this you can open the file from your text editor's menu: this way you avoid Windows guessing how to open the file.

• By default restricted shell escape is enabled. So some external programmes can be run within certain constraints. I think, but am not sure, that -no-shell-escape is more restrictive. This all goes for TeX Live. I've no idea about MiKTeX. – cfr Sep 15 '14 at 17:16

To expand a bit on the other answers, a .texfile is the same file format as .txt from the operating system's perspective. Both are plain text files.

A plain text file contains nothing but series of character-codes, which a text editor tells the computer to display as letters according to the codes. There are different encodings, with UTF-8 being now used almost universally. There is no invisible data or metadata (except the filename itself, the timestamp, etc., which are specific to the operating system).

You can take a .txt file and change the suffix to .tex, or vice versa, and nothing changes except the filename. It is just a convention to name the files this way. If given a filename without an extension, the TeX engines will look for a .tex; but otherwise it doesn't matter.

You can create the .tex file in any editor, not just a special TeX program. On a Unix-like system, you can even create one from the command line.

• RE: The last sentence: Windows can do it too! :-) – Paul Gessler Sep 15 '14 at 16:48