or
Community
I've just been asked to add an MWE, what is that?
Top Answer
Community
# What is an MWE?

A minimal working example (MWE) is a short test document that contains everything necessary to compile (e.g. `\documentclass{...}`, the necessary packages etc.) while still producing the error/problem you are asking about. 

# Some important points

- remember that we don't have access to your computer. Try to avoid images or included files in your MWE which we don't have. If you need things like images in your document etc to reproduce the problem, have a look at the files from packages like `MWE` or `duckuments`. These are included in most latex installations

- try to avoid custom classes and packages if you can also reproduce the problem with standard classes and packages. If some custom class or package that is not available from ctan is essential to reproduce the problem, please add a link where we can download the same version of the class/package you are using. 

- If you are using special fonts, right-to-left typesetting, special engines etc. check if you can also reproduce your problem without these things, this will increase the number of users who can try to help you.

- you might have concerns sharing you unpublished text on the internet. That is totally fine, we are not interested in the content of your document, probably most of can be removed in the creation of an MWE. If you need text to reproduce the problem, you can replace your own words with dummy text like lorem lipsum. There are several latex packages that will help you with that, for example `duckuments`, `lipsum`, `blindtext` and many more (https://ctan.org/topic/dummy-gen)

- "Is this a bad joke, my document is not working, how should I create a working example? If I were to know how to make it working, I would not be asking here" The name is probably a bit misleading, your document does not need to be working without error, but it should have all the necessary bits to work in theory if the error would not be there.

# Why should I add an MWE?

By adding an MWE you help both the people who try to help you and yourself

- An MWE is often essential to be able to solve a TeX problem. If you just describe the symptoms (for example "My document is suddenly in italic"), there might be many different causes and users can only guess what might or might not be the specific problem in your document. With an MWE the users trying to help you can see in your code what the problem really is.

- During the process of creating an MWE you will often be able to solve the problem yourself. Even though your problem is solved, please consider writing a questions and self answer if you think other users might face the same problem.

- Showing an MWE has the additional benefit that it often also shows your experience level in TeX. This might help users to tailor their answers to your needs.

- With an MWE you use the time of the users willing to help you efficiently. They don't have to spend time trying to reproduce your problem before even starting to work on a solution and you save them from the boring task of typing things like `\documentclass` for the 1000th time. In exchange this will cost you a bit more time, yes, but please remember that the other users invest their spare time for free when they try to help you, so it is a nice gesture to make it as easy as possible for them. It also helps to avoid unnecessary duplication of the work if multiple users try to help you and each of them would have to create their own MWE.

- With an MWE more people will be able help you because this combines the knowledge from the users willing to help you with yours. For example if you face a problem with some exotic package, then an MWE will show the other users how this package works and they can immediately start working on a solution for you. Without an MWE you are limited to either the users that already know your exotic package or are willing to spend some time learning it before even starting to work on an answer.

# How to create an MWE

There are at least two approaches

- Divide and conquer: Make a copy of your document and start to remove things unnecessary to reproduce the problem. A good strategy is bisecting: remove one half of the document and test if the problem is still there. If yes, repeat this step and remove half of the remaining document etc. If the error is gone, undo the last step and try to remove the other half. Repeat this until you have an MWE.

- Build from scratch: Create a simple test document that compiles without problems. Then start copying bits and pieces from your real document into the test document until your problem also appears in your test document. This should give a good idea where the problem comes from and you can again remove everything from your test document that is not necessary to reproduce the problem.

# Example

```
\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum} % to generate dummy text in this MWE

\begin{document}

\lipsum

\begin{figure}[htb]
 \centering
 \includegraphics{example-image-duck}% <- use some graphics that ship with the 
 \caption{A figure.} % usual TeX installations rather than some others won't have
\end{figure}
\end{document}
```
Answer #2
Community
# MWE with bibliographies (MWEB)

In general the tips from https://topanswers.xyz/tex?q=606#a664 also apply to MWEs with bibliographies (MWEB). For many users it might seem harder to create an MWEB, because they often depend on external `.bib`. Therefore this answer will give some concrete examples differentiating between different bibliography tools.

While creating an MWEB remember to compile often enough (including running bibliography tools like bibtex/biber if applicable) because many changes will only take effect multiple compilations.

## `thebibliography` environment

This is the easiest case because no additional files are involved. 

```
\documentclass{article}

\begin{document}

text \cite{texbook} text

\begin{thebibliography}{9}
\bibitem{texbook} 
  Donald Ervin Knuth. 
  \textit{The \TeX book}. 
  Addison-Wesley, Reading, Massachusetts, 1983.
\end{thebibliography}

\end{document}
```

## BibTeX

### Sample `.bib` file

If the problem is not related to the content of the `.bib` file, most tex distributions come with several sample `.bib` files that can be used to demonstrate your problem. One possibility is `xampl.bib`[^*] :  

```
\documentclass{article}

\begin{document}

text \cite{book-full}
 
\bibliographystyle{unsrt}
\bibliography{xampl}

\end{document}
```

### Own `.bib` file

If the problem is connected to a specific bib entry, the users trying to help you will need to see this entry. To save them from having to manually create a new `.bib` file and copy the entry there, it is very helpful to use the `filecontents`[^**] environment that will automatically create a new file with the desired content.

```
\documentclass{article}

\begin{filecontents}{\jobname.bib}
@book{knuth:ct:a,
  author       = {Knuth, Donald E.},
  title        = {The {\TeX book}},
  year         = 1984,
  maintitle    = {Computers \& Typesetting},
  volume       = {A},
  publisher    = {Addison-Wesley},
}
\end{filecontents}

\begin{document}

text \cite{knuth:ct:a} text
 
\bibliographystyle{unsrt}
\bibliography{\jobname}

\end{document}
```

## Biblatex

### Sample `.bib` file

If the problem is not related to the content of the `.bib` file, one can use `biblatex-examples.bib` in the MWEB[^*]. This is a demo `.bib` file included in most latex installations which has examples for many different types of entries. 

```
\documentclass{article}

\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}

\begin{document}

text \cite{knuth:ct:a} text

\printbibliography

\end{document}
```

### Own `.bib` file

If the problem is connected to a specific bib entry, the users trying to help you will need to see this entry. To save them from having to manually create a new `.bib` file and copy the entry there, it is very helpful to use the `filecontents`[^**] environment that will automatically create a new file with the desired content.

```
\documentclass{article}

\usepackage{biblatex}

\begin{filecontents}{\jobname.bib}
@book{knuth:ct:a,
  author       = {Knuth, Donald E.},
  title        = {The {\TeX book}},
  date         = 1984,
  maintitle    = {Computers \& Typesetting},
  volume       = {A},
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting A},
  indexsorttitle= {The TeXbook},
  indextitle   = {\protect\TeX book, The},
  shorttitle   = {\TeX book},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

text \cite{knuth:ct:a} text

\printbibliography

\end{document}
```

[^*]: In order to inspect the sample `.bib` one can use `kpsewhich <filename>.bib`, e.g. `kpsewhich biblatex-examples.bib`, from a command line to get the location of the file and then use your favourite editor to open it

[^**]: The `filecontents` environment doesn't overwrite existing files. The proposed filename `\jobname.bib` will result in a `.bib` file with the same base name as your main `.tex`.
Minimal working example
samcarter replying to Skillmon
:) thanks
Skillmon replying to samcarter
so I did :)
samcarter replying to Skillmon
Feel free to edit!
samcarter replying to Skillmon
I know. I'm more worried about it not working.
Skillmon replying to samcarter
I think `\jobname.bib` is safer, after all everybody intending to help will use a specific file name in his temporary directory.
Skillmon replying to samcarter
`filecontents` doesn't overwrite existing files. 
samcarter replying to Skillmon
I was thinking about this. The question is what will more likely cause problems with existing files of the same name? I'm afraid users might ignore the warning that the file already exists and will not be overwritten and then wonder why the example does not work as expected? Another thought would be to use some cryptic letter combination.
Skillmon
Also we should use `\jobname.bib` for the `filecontents` solutions, I'd say.
Skillmon replying to samcarter
Also `kpsewhich` by default only returns a single file, which is the one actually used, if there are multiple files with the same name.
samcarter replying to Skillmon
updated, thanks! (even though windows users deserve no sympathy :)
Skillmon replying to samcarter
One should use `kpsewhich`, I think I remember that Ulrike once told me that `kpsewhere` isn't contained on Windows, whereas `kpsewhich` is.
samcarter replying to Skillmon
added a footnote on how to locate the files
samcarter replying to Skillmon
I did not send it, just drafted it in reply to your question
Skillmon replying to samcarter
where's that comment? Can't find it in this thread. I'd also use "an MWE" naturally instead of "a MWE".
samcarter replying to Skillmon
Thanks for the research! 
samcarter replying to Skillmon
I had a long comment written that I would favour `a`, but the ultimate reference on all things about language uses `an` http://www.gust.org.pl/bachotex/2017-pl/presentations/bbeeton-1-2017.pdf
Skillmon replying to samcarter
apparently it is: https://github.com/MiKTeX/miktex/issues/294 (at least on Mac)
Skillmon
And do we use "a MWE" or "an MWE"? I still don't know for sure which is right, but we should be consistent on it :)
Skillmon replying to samcarter
I don't know, I know it is on TeX Live for Windows.
samcarter replying to Skillmon
Is kpsewhich available for miktex?
Skillmon replying to samcarter
maybe we should also tell the users how they can find the information contained in the example bib-files. It's hard to use them if you don't know which keys are available. We could keep that rather short by telling them to use `kpsewhich` to find the file and take a look with their favourite editor. What do you say?
samcarter
@Skillmon FYI: I added a first draft for MWE with bibliographies. Please feel free to change/amend it as you like.
samcarter replying to Skillmon
Good luck with your thesis!
samcarter replying to marmot
thanks!
marmot replying to samcarter
I added something.
Skillmon replying to samcarter
I don't have the time right now. Trying to code some things for my master's thesis.
samcarter replying to Skillmon
Another answer about MWE with bib is on my todo list, but don't know the ETA. If you would like to start writing one, should I make another answer with the community user that you can edit?  
samcarter replying to CarLaTeX
Thanks :) I see a MWE is now in the questions, so it seems to have worked in at least one case...
samcarter replying to marmot
Your argument makes sense, I'm just not creative enough to come up with a better example. I removed the missing `$` for the time being, please feel free to come up with another example. 
Skillmon replying to samcarter
Should we add other answers for more specific MWEs, e.g., in the "How to create" section list things like "MWE with bib" and have that link to another answer that shows MWEs with bibs for `bibtex`, `natbib` and `biblatex`, etc. always including one of the example .bib-files contained in TeX Live?
CarLaTeX
@samcarter I think your explanation of a MWE is better than the one on TeX.SE Meta, so I linked it here: https://tex.stackexchange.com/questions/525578/multiple-alignments-within-tables?noredirect=1#comment1329431_525578
marmot replying to samcarter
I think so, yes. Not because it is not useful, but because it is maybe not *that* useful. What I mean is that I would like this site to become something where we post really interesting question, and not so much fix missing `$` signs. If you want me to I'll be happy to add an example.
samcarter
The second time I could always blame myself for not posting the MWE the first time :)
samcarter replying to Skillmon
It can even happen that the same user spends this second multiple times: It happened more than once that I reduced some code to a MWE just to realise that I could not solve the problem, but some time later I had a new idea and had again to create a MWE :)
samcarter replying to Skillmon
Good point!
samcarter replying to Skillmon
Yes, the `$` is missing on purpose to show that the mwe does not necessarily compile. Would it be better without the error?
Skillmon replying to samcarter
is the closing `$` in the MWE missing on purpose?
Skillmon replying to samcarter
The paragraph "With an MWE you use the time of the users [...]" could also reason with the overall spent time, one user spending a second is less time than 10 users each spending a second.
samcarter
@all I posted this under a dummy account to encourage you all to edit and expand this